워크플로 구축하기

개발자를 위한 Python 입문

Jasmin Ludolf

Senior Data Science Content Developer

복잡한 워크플로

  • 데이터 구조 순회
    • for, while
  • 여러 조건 평가
    • if, elif, else, >, >=, <, <=, ==, !=
  • 변수 업데이트
    • +=
  • 반환 출력
    • print()
개발자를 위한 Python 입문

'in' 키워드

  • in = 값이 변수/데이터 구조에 있는지 확인합니다
recipe = {"pasta": 500, "tomatoes": 400, 
          "garlic": 15, "basil": 20}

if "pasta" in recipe.keys(): print(True) else: print(False)
True
  • 모든 키를 반복하는 것보다 더 빠릅니다
개발자를 위한 Python 입문

'not' 키워드

  • 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
개발자를 위한 Python 입문

'and' 키워드

  • 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
개발자를 위한 Python 입문

'or' 키워드

  • 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
개발자를 위한 Python 입문

변수에 더하기/빼기

  • 키워드를 다른 기법과 결합해 복잡한 워크플로 구축하기
ingredients_checked = 0
for ingredient in recipe_list:
    # ingredients_checked = ingredients_checked + 1
    ingredients_checked += 1

items_to_buy = 10 for item in shopping_list: # items_to_buy = items_to_buy - 1 items_to_buy -= 1
  • +=는 변수에 더하고 -=는 변수에서 뺍니다
  • 변수를 업데이트하는 다른 방법
개발자를 위한 Python 입문

추가하기

  • 특정 기준을 충족하는 정보를 리스트에 저장합니다
# 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)
개발자를 위한 Python 입문

추가하기

print(shopping_list)
['tomatoes', 'salt']
개발자를 위한 Python 입문

연습해 봅시다!

개발자를 위한 Python 입문

Preparing Video For Download...