Introducción a Python para desarrolladores
Jasmin Ludolf
Senior Data Science Content Developer
for, whileif, elif, else, >, >=, <, <=, ==, !=+=print()in = comprueba si un valor está en una variable/estructurarecipe = {"pasta": 500, "tomatoes": 400, "garlic": 15, "basil": 20}if "pasta" in recipe.keys(): print(True) else: print(False)
True
not = comprueba si una condición no se cumplepantry_items = ["flour", "sugar", "olive oil"]# Comprueba si "salt" NO está en la despensa if "salt" not in pantry_items: print(True) else: print(False)
True
and = comprueba si se cumplen varias condicionespasta_quantity = 600 olive_oil_quantity = 30# Comprueba si tenemos suficientes de AMBOS ingredientes if pasta_quantity >= 500 and olive_oil_quantity >= 30: print(True) else: print(False)
True
or = comprueba si se cumple una (o más) condiciónpasta_quantity = 600 olive_oil_quantity = 30# Comprueba si tenemos suficientes de CUALQUIERA de los ingredientes if pasta_quantity >= 500 or olive_oil_quantity >= 30: print(True) else: print(False)
True
ingredients_checked = 0 for ingredient in recipe_list: # ingredients_checked = ingredients_checked + 1 ingredients_checked += 1items_to_buy = 10 for item in shopping_list: # items_to_buy = items_to_buy - 1 items_to_buy -= 1
+= suma a una variable, -= resta# Crea una lista vacía para los resultados shopping_list = []# Recorre los ingredientes de la receta for ingredient, qty_needed in recipe.items():# Comprueba si hay que comprarlo if ingredient not in pantry:# Añade a la lista de la compra shopping_list.append(ingredient)
print(shopping_list)
['tomatoes', 'salt']
Introducción a Python para desarrolladores