Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| Ambdós costats versió prèvia Revisió prèvia Següent revisió | Revisió prèvia | ||
| info:cursos:udemy:python-mega-course [09/10/2024 02:22] – [Cheatsheet: Loops] mate | info:cursos:udemy:python-mega-course [18/10/2024 04:12] (actual) – [Curso python udemy] mate | ||
|---|---|---|---|
| Línia 1: | Línia 1: | ||
| = Curso python udemy | = Curso python udemy | ||
| + | * [[https:// | ||
| + | == interesante | ||
| + | * Numpy: manejo de matrices | ||
| + | * Web Mapping: creación mapas interactivos HTML | ||
| + | * Manejo Webcam | ||
| + | * Bokeh: libreria representación gráficos -> [[development: | ||
| + | * Pandas: libreria de analisis de datos -> [[development: | ||
| + | * Flask: web development | ||
| + | * openCV: image processing library | ||
| + | * Mobile app: apk | ||
| + | * Web Scraping | ||
| + | * pyinstaller: | ||
| + | |||
| + | == jupyter notebook | ||
| + | * <code bash> | ||
| + | * <code bash> | ||
| + | * <code bash> | ||
| == Cheatsheet: Data Types | == Cheatsheet: Data Types | ||
| * Integers are used to represent whole numbers:< | * Integers are used to represent whole numbers:< | ||
| Línia 206: | Línia 223: | ||
| * A basic list comprehension:< | * A basic list comprehension:< | ||
| - | [i*2 for i in [1, 5, 10]]</ | + | [i*2 for i in [1, 5, 10]]</ |
| [2, 10, 20]</ | [2, 10, 20]</ | ||
| * List comprehension with if condition:< | * List comprehension with if condition:< | ||
| - | [i*2 for i in [1, -2, 10] if i> | + | [i*2 for i in [1, -2, 10] if i> |
| [2, 20]</ | [2, 20]</ | ||
| * List comprehension with an if and else condition:< | * List comprehension with an if and else condition:< | ||
| - | [i*2 if i>0 else 0 for i in [1, -2, 10]]</ | + | [i*2 if i>0 else 0 for i in [1, -2, 10]]</ |
| [2, 0, 20]</ | [2, 0, 20]</ | ||
| + | == Cheatsheet: More on Functions | ||
| + | * Functions can have more than one parameter:< | ||
| + | def volume(a, b, c): | ||
| + | return a * b * c</ | ||
| + | |||
| + | * Functions can have default parameters (e.g. coefficient):< | ||
| + | def converter(feet, | ||
| + | meters = feet / coefficient | ||
| + | return meters | ||
| + | |||
| + | print(converter(10)) | ||
| + | # Output: 3.0480370641306997 | ||
| + | </ | ||
| + | |||
| + | * Arguments can be passed as non-keyword (positional) arguments (e.g. a) or keyword arguments (e.g. b=2 and c=10):< | ||
| + | def volume(a, b, c): | ||
| + | return a * b * c | ||
| + | |||
| + | print(volume(1, | ||
| + | </ | ||
| + | |||
| + | * An *args parameter allows the function to be called with an arbitrary number of non-keyword arguments:< | ||
| + | def find_max(*args): | ||
| + | return max(args) | ||
| + | print(find_max(3, | ||
| + | # Output: 1001 | ||
| + | </ | ||
| + | |||
| + | * A %%**%%kwargs parameter allows the function to be called with an arbitrary number of keyword arguments:< | ||
| + | def find_winner(**kwargs): | ||
| + | return max(kwargs, key = kwargs.get) | ||
| + | |||
| + | print(find_winner(Andy = 17, Marry = 19, Sim = 45, Kae = 34)) | ||
| + | # Output: Sim | ||
| + | </ | ||
| + | |||
| + | * Here's a summary of function elements: | ||
| + | |||
| + | == Cheatsheet: File Processing | ||
| + | * You can read an existing file with Python:< | ||
| + | with open(" | ||
| + | content = file.read() | ||
| + | </ | ||
| + | |||
| + | * You can create a new file with Python and write some text on it:<code python> | ||
| + | with open(" | ||
| + | content = file.write(" | ||
| + | </ | ||
| + | * You can append text to an existing file without overwriting it:<code python> | ||
| + | with open(" | ||
| + | content = file.write(" | ||
| + | |||
| + | * You can both append and read a file with:< | ||
| + | with open(" | ||
| + | content = file.write(" | ||
| + | file.seek(0) | ||
| + | content = file.read() | ||
| + | </ | ||
| + | | ||
| + | == Cheatsheet: Imported Modules | ||
| + | * Builtin objects are all objects that are written inside the Python interpreter in C language. | ||
| + | * Builtin modules contain builtins objects. | ||
| + | * Some builtin objects are not immediately available in the global namespace. They are parts of a builtin module. To use those objects the module needs to be imported first. E.g.:< | ||
| + | import time | ||
| + | time.sleep(5) | ||
| + | </ | ||
| + | * A list of all builtin modules can be printed out with:< | ||
| + | import sys | ||
| + | sys.builtin_module_names | ||
| + | </ | ||
| + | * Standard libraries is a jargon that includes both builtin modules written in C and also modules written in Python. | ||
| + | * Standard libraries written in Python reside in the Python installation directory as .py files. You can find their directory path with '' | ||
| + | * Packages are a collection of .py modules. | ||
| + | * Third-party libraries are packages or modules written by third-party persons (not the Python core development team). | ||
| + | * Third-party libraries can be installed from the terminal/ | ||
| + | * Windows:< | ||
| + | pip install pandas # or use | ||
| + | python -m pip install pandas # if that doesn' | ||
| + | </ | ||
| + | * Mac and Linux:< | ||
| + | pip3 install pandas # or use | ||
| + | python3 -m pip install pandas # if that doesn' | ||
| + | </ | ||
| + | |||
| + | == Flask | ||
| + | <code bash>pip install Flask</ | ||
| + | |||
| + | <code python script1.py> | ||
| + | from flask import Flask, render_template | ||
| + | |||
| + | app=Flask(__name__) | ||
| + | |||
| + | @app.route("/" | ||
| + | def home(): | ||
| + | return render_template(" | ||
| + | |||
| + | @app.route("/ | ||
| + | def about(): | ||
| + | return render_template(" | ||
| + | |||
| + | if __name__==" | ||
| + | app.run(debug=True) | ||
| + | </ | ||
| + | |||
| + | <code html templates/ | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <link rel=" | ||
| + | </ | ||
| + | < | ||
| + | < | ||
| + | <div class=" | ||
| + | <h1 class=" | ||
| + | <ul class=" | ||
| + | < | ||
| + | < | ||
| + | </u1> | ||
| + | </ | ||
| + | </ | ||
| + | <div class=" | ||
| + | {%block content%} | ||
| + | {%endblock%} | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | <code html templates/ | ||
| + | {%extends " | ||
| + | {%block content%} | ||
| + | < | ||
| + | {%endblock%} | ||
| + | </ | ||
| + | |||
| + | <code html templates/ | ||
| + | {%extends " | ||
| + | {%block content%} | ||
| + | < | ||
| + | {%endblock%} | ||
| + | </ | ||
| + | |||
| + | <code css static/ | ||
| + | body { | ||
| + | margin: 0; | ||
| + | padding: 0; | ||
| + | font-family: | ||
| + | color: #060; | ||
| + | } | ||
| + | |||
| + | /* | ||
| + | * Formatting the header area | ||
| + | */ | ||
| + | |||
| + | header { | ||
| + | background-color: | ||
| + | height: 35px; | ||
| + | width: 100%; | ||
| + | opacity: .9; | ||
| + | margin-bottom: | ||
| + | } | ||
| + | |||
| + | header h1.logo { | ||
| + | margin: 0; | ||
| + | font-size: 1.7em; | ||
| + | color: #fff; | ||
| + | text-transform: | ||
| + | float: left; | ||
| + | } | ||
| + | |||
| + | header h1.logo: | ||
| + | color: #fff; | ||
| + | text-decoration: | ||
| + | } | ||
| + | |||
| + | /* | ||
| + | * Center the body content | ||
| + | */ | ||
| + | |||
| + | .container { | ||
| + | width: 1200px; | ||
| + | margin: 0 auto; | ||
| + | } | ||
| + | |||
| + | div.home { | ||
| + | padding: 10px 0 30px 0; | ||
| + | background-color: | ||
| + | -webkit-border-radius: | ||
| + | | ||
| + | border-radius: | ||
| + | } | ||
| + | |||
| + | div.about { | ||
| + | padding: 10px 0 30px 0; | ||
| + | background-color: | ||
| + | -webkit-border-radius: | ||
| + | | ||
| + | border-radius: | ||
| + | } | ||
| + | |||
| + | h2 { | ||
| + | font-size: 3em; | ||
| + | margin-top: 40px; | ||
| + | text-align: center; | ||
| + | letter-spacing: | ||
| + | } | ||
| + | |||
| + | h3 { | ||
| + | font-size: 1.7em; | ||
| + | font-weight: | ||
| + | margin-top: 30px; | ||
| + | text-align: center; | ||
| + | letter-spacing: | ||
| + | color: #999; | ||
| + | } | ||
| + | |||
| + | .menu { | ||
| + | float: right; | ||
| + | margin-top: 8px; | ||
| + | } | ||
| + | |||
| + | .menu li { | ||
| + | display: inline; | ||
| + | } | ||
| + | |||
| + | .menu li + li { | ||
| + | margin-left: | ||
| + | } | ||
| + | |||
| + | .menu li a { | ||
| + | color: #444; | ||
| + | text-decoration: | ||
| + | } | ||
| + | |||
| + | </ | ||