








Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Prepara tus exámenes
Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Prepara tus exámenes con los documentos que comparten otros estudiantes como tú en Docsity
Encuentra los documentos específicos para los exámenes de tu universidad
Estudia con lecciones y exámenes resueltos basados en los programas académicos de las mejores universidades
Responde a preguntas de exámenes reales y pon a prueba tu preparación
Consigue puntos base para descargar
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Comunidad
Pide ayuda a la comunidad y resuelve tus dudas de estudio
Ebooks gratuitos
Descarga nuestras guías gratuitas sobre técnicas de estudio, métodos para controlar la ansiedad y consejos para la tesis preparadas por los tutores de Docsity
This cheat sheet includes the materials I’ve covered in my Python tutorial for Beginners on YouTube. Both the YouTube tutorial and this cheat cover the core language constructs but they are not complete by any means.
Tipo: Apuntes
1 / 14
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!









Variables
price = 10 rating = 4. course_name = ‘Python for Beginners’ is_published = True
Receiving Input
birth_year = int(input(‘Birth year: ‘))
contains = ‘Python’ in course Arithmetic Operations
/ # returns a float // # returns an int % # returns the remainder of division ** # exponentiation - x ** y = x to the power of y
x = x + 10 x += 10
If Statements if is_hot: print(“hot day”) elif is_cold: print(“cold day”) else: print(“beautiful day”)
if has_high_income and has_good_credit: ... if has_high_income or has_good_credit: ... is_day = True is_night = not is_day Comparison operators a > b a >= b (greater than or equal to) a < b a <= b a == b (equals) a != b (not equals) While loops i = 1 while i < 5 : print(i) i += 1
Dictionaries
customer = { “name”: “John Smith”, “age”: 30 , “is_verified”: True }
customer[“name”] # returns “John Smith” customer[“type”] # throws an error customer.get(“type”, “silver”) # returns “silver” customer[“name”] = “new name” Functions
def greet_user(name): print(f”Hi {name}”) greet_user(“John”)
greet_user(“John”, “Smith”)
calculate_total(order= 50 , shipping= 5 , tax=0.1)
def square(number): return number * number result = square(2) print(result) # prints 4 Exceptions
try: age = int(input(‘Age: ‘)) income = 20000 risk = income / age print(age) except ValueError: print(‘Not a valid number’) except ZeroDivisionError: print(‘Age cannot be 0’) Classes
class Point: def init(self, x, y): self.x = x self.y = y def move(self): print(“move”)
import converters converters.kg_to_lbs(5)
from converters import kg_to_lbs kg_to_lbs(5) Packages
from ecommerce import sales sales.calc_shipping()
from ecommerce.sales import calc_shipping calc_shipping() Python Standard Library
Random Module import random random.random() # returns a float between 0 to 1 random.randint(1, 6 ) # returns an int between 1 to 6 members = [‘John’, ‘Bob’, ‘Mary’] leader = random.choice(members) # randomly picks an item
Pypi
pip install openpyxl pip uninstall openpyxl Want to Become a Python Expert?