- 매개변수란?
- 컴퓨터 프로그래밍에서 매개변수란 변수의 특별한 한 종류로서, 함수 등과 같은 서브루틴의 인풋으로 제공되는 여러 데이터 중 하나를 가리키기 위해 사용
- Python 매개변수의 종류
- 위치 매개변수
- 기본 매개변수
- 키워드 매개변수
- 위치 가변 매개변수
- 키워드 가변 매개변수
- Python 매개변수의 작성 순서
- 위치 – 기본 – 위치 가변 – 키워드(기본) – 키워드 가변
def post_info(title, content):
print(f"{title} : {content}")
post_info("어벤져스", "3천만큼 사랑해")
# 어벤져스 : 3천만큼 사랑해
def post_info(title, content = None):
if content == None: print(f"{title}")
else: print(f"{title} : {content}")
post_info("어벤져스")
# 어벤져스
def post_info(title, content):
print(f"{title} : {content}")
post_info(content="도르마무 거래를 하러왔다", title="닥터 스트레인지")
# 닥터 스트레인지 : 도르마무 거래를 하러왔다
def post_info(*args):
print(args)
post_info("왕좌의 게임", "마더", "파라노말 액티비티", "집으로")
# ('왕좌의 게임', '마더', '파라노말 액티비티', '집으로')
def post_info(**kwargs):
print(kwargs)
for key, value in kwargs.items():
print(f"{key} : {value}")
post_info(name = "왕좌의 게임", content="King in the North!")
"""
name : 왕좌의 게임
content : The King in the North!
"""