함수
def open_account():
print("새로운 계좌가 생성되었습니다.")
open_account()
전달값과 반환값
def open_account():
print("새로운 계좌가 생성되었습니다.")
def deposit(balance, money):
print("입금이 완료되었습니다. 잔액은 {0}원입니다.".format(balance+money))
return balance+money
def withdraw(balance, money):
if balance>=money:
print("출금이 완료되었습니다. 잔액은 {0}원 입니다.".format(balance-money))
return balance-money
else:
print("출금이 살패했습나다.".format(balance))
return balance
def withdraw_commission(balance, money):
commission=100
return commission, balance-money-commission
balance = 0
balance = deposit(balance,1000)
balance = withdraw(balance,1000)
commission, balance=withdraw_commission(balance, 500)
print("수수료는 {0}원이고 잔액은 {1}원입니다.".format(commission, balance))
기본값
def profile(name, age=17, main_lang="파이썬"):
print("이름 : {0}\t나이 : {1}\t주 사용 언어 : {2}\t".format(name, age, main_lang))
profile("정은하")
키워드
def profile(name, age, main_lang):
print(name, age, main_lang)
profile(name="정은하",age=24, main_lang="파이썬")
가변인자
def profile(name, age, *language):
print("이름 : {0}\t나이 : {1}\t".format(name, age),end=" ")
for lang in language:
print(lang, end=" ")
print()
profile("정은하",24,"파이썬","자바","코틀린")
profile("이은하",22,"파이썬","자바")