파이썬 return.
함수 내에서 return 은 그 함수가 실행할 수 있는 마지막 부분이라고 생각하면 된다.
즉, 함수 실행 시 return을 만나면 그 즉시 해당 함수는 종료된다.
그리고 return 을 이용해서 원하는 값을 output할 수 있다.
#return
def tax_calc(money):
return money * 0.1
def pay_tax(tax):
print('thank you for paying', tax)
to_pay = tax_calc(10000)
pay_tax(to_pay)
#return 2
def make_juice(fruit):
return f"{fruit} + juice" # apple + juice
def add_ice(juice):
return f"{juice} + Ice" # apple + juice + Ice
def add_sugar(iced_juice):
return f"{iced_juice} + sugar" # aple + juice + Ice + sugar
juice = make_juice("apple")
cold_juice = add_ice(juice)
perfect_juice = add_sugar(cold_juice)
print(perfect_juice)
[Python] data structure ( 데이터 구조 ) (2) | 2024.01.16 |
---|---|
[Python] while 문, if elif else 문 (0) | 2024.01.15 |
[Python] 파이썬 계산기 연습 (0) | 2024.01.15 |
[Python] default Parameter (디폴트 파라미터) (1) | 2024.01.15 |
[python] 함수 (0) | 2024.01.12 |