[Python] 함수
[Python] 함수
Inflearn Study
- 인프런에서 “파이썬 무료 강의 (기본편) - 6시간 뒤면 나도 개발자” 강의를 들으며 혼자 공부한 내용입니다.
함수
def open_count(): # 입력값과 반환값이 없는 함수
print("새로운 계좌가 생성되었습니다.")
open_count()
-
def 함수 이름():
수행 문장
입력값만 있는 함수
def deposit(balance, money):
print("입금이 완료되었습니다. 잔액은 {0}원입니다.".format(balance+money))
deposit(0, 2000)
-
def 함수 이름(매개변수1, … ):
수행 문장
반환값만 있는 함수
def my_balance():
return 0
balance = my_balance()
print(balance)
-
def 함수 이름():
수행 문장
return 반환 값
입력값과 반환값이 있는 함수
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("출금이 완료되지않았습니다. 잔액은 {0}원입니다.".format(balance))
return balance
def withdraw_night(balance, money):
commission = 100 # 수수료
return commission, balance-money-commission
balance = 0 # 잔액
balance = deposit(balance, 1000)
# balance = withdraw(balance, 2000)
commission, balance = withdraw_night(balance, 500)
print("수수료 {0}원이며 잔액은 {1}원 입니다.".format(commission, balance))
-
def 함수 이름(매개변수1, … ):
수행 문장
return 반환 값
Leave a comment