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:08] – [Cheatsheet: Operations with Data Types] 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 112: | Línia 129: | ||
| print(" | print(" | ||
| </ | </ | ||
| + | |||
| * Write if-elif-else conditionals:< | * Write if-elif-else conditionals:< | ||
| message = "hello there" | message = "hello there" | ||
| Línia 155: | Línia 172: | ||
| </ | </ | ||
| + | | ||
| + | == Cheatsheet: Loops | ||
| + | A for-loop is useful to repeatedly execute a block of code. | ||
| + | |||
| + | * You can create a for-loop like so:<code python> | ||
| + | for letter in ' | ||
| + | print(letter.upper()) | ||
| + | </ | ||
| + | A | ||
| + | B | ||
| + | C | ||
| + | </ | ||
| + | * As you can see, the for-loop repeatedly converted all the items of ' | ||
| + | * The name after for (e.g. letter) is just a variable name | ||
| + | * You can loop over dictionary keys as follows:< | ||
| + | phone_numbers = {"John Smith":" | ||
| + | for value in phone_numbers.keys(): | ||
| + | print(value) | ||
| + | </ | ||
| + | John Smith | ||
| + | Marry Simpsons | ||
| + | </ | ||
| + | |||
| + | * You can loop over dictionary values:< | ||
| + | phone_numbers = {"John Smith":" | ||
| + | for value in phone_numbers.values(): | ||
| + | print(value) | ||
| + | </ | ||
| + | +37682929928 | ||
| + | +423998200919 | ||
| + | </ | ||
| + | |||
| + | * You can loop over dictionary items:< | ||
| + | phone_numbers = {"John Smith":" | ||
| + | for key, value in phone_numbers.items(): | ||
| + | print(key, value) | ||
| + | </ | ||
| + | John Smith +37682929928 | ||
| + | Marry Simpons +423998200919 | ||
| + | </ | ||
| + | |||
| + | * We also have while-loops. The code under a while-loop will run as long as the while-loop condition is true:< | ||
| + | while datetime.datetime.now() < datetime.datetime(2090, | ||
| + | print(" | ||
| + | </ | ||
| + | * The loop above will print out the string inside print() over and over again until the 20th of August, 2090. | ||
| + | |||
| + | == Cheatsheet: List Comprehensions | ||
| + | A list comprehension is an expression that creates a list by iterating over another container. | ||
| + | |||
| + | * A basic list comprehension:< | ||
| + | [i*2 for i in [1, 5, 10]]</ | ||
| + | [2, 10, 20]</ | ||
| + | |||
| + | * List comprehension with if condition:< | ||
| + | [i*2 for i in [1, -2, 10] if i> | ||
| + | [2, 20]</ | ||
| + | |||
| + | * List comprehension with an if and else condition:< | ||
| + | [i*2 if i>0 else 0 for i in [1, -2, 10]]</ | ||
| + | [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: | ||
| + | } | ||
| + | |||
| + | </ | ||