개발자를 위한 Python 입문
Jasmin Ludolf
Senior Data Science Content Developer
for, whileif, elif, else, >, >=, <, <=, ==, !=+=print()in = 값이 변수/데이터 구조에 있는지 확인합니다recipe = {"pasta": 500, "tomatoes": 400, "garlic": 15, "basil": 20}if "pasta" in recipe.keys(): print(True) else: print(False)
True
not = 조건이 충족되지 않았는지 확인합니다pantry_items = ["flour", "sugar", "olive oil"]# Check if "salt" is NOT in our pantry if "salt" not in pantry_items: print(True) else: print(False)
True
and = 여러 조건이 충족되는지 확인합니다pasta_quantity = 600 olive_oil_quantity = 30# Check if we have enough of BOTH ingredients if pasta_quantity >= 500 and olive_oil_quantity >= 30: print(True) else: print(False)
True
or = 하나(또는 그 이상)의 조건이 충족되는지 확인합니다pasta_quantity = 600 olive_oil_quantity = 30# Check if we have enough of EITHER ingredient 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
+=는 변수에 더하고 -=는 변수에서 뺍니다# Create empty list to hold results shopping_list = []# Loop through recipe ingredients for ingredient, qty_needed in recipe.items():# Check if we need to buy it if ingredient not in pantry:# Add to shopping list shopping_list.append(ingredient)
print(shopping_list)
['tomatoes', 'salt']
개발자를 위한 Python 입문