# [TIL]Function Parameters1

newjinnyยท2021๋ 10์ 12์ผ
0

## python

๋ชฉ๋ก ๋ณด๊ธฐ
2/4

๐ default value parameter : ํจ์๋ฅผ ์ ์ํ  ๋ parameter์ ๊ธฐ๋ณธ ๊ฐ์ ์ง์ ํด์ฃผ๋ฉด ํธ์ถํ  ๋ argument๋ฅผ ๋ฃ์ง ์์๋ ๊ธฐ๋ณธ๊ฐ์ด ํ ๋น ๋๋ค.

๐ variable length arguments : ์ธ์์ ๊ฐ์๊ฐ ๋ณํ  ์ ์๋ค๋ ์๋ฏธ๋ก, ํจ์๋ฅผ ํธ์ถํ  ๋ ์ธ์์ ๊ฐ์๋ฅผ ๋ค์ํ๊ฒ ๋ฐ๊ฟ๊ฐ๋ฉฐ ์ ๋ฌํ  ์ ์๋ ๋ฐฉ์์ด๋ค.

๐ positional arguments : ํจ์๋ฅผ ํธ์ถํ  ๋ ์ ๋ฌ๋๋ ๊ฐ์ด ์ธ์๋ค์ด ๋งค๊ฐ๋ณ์ ์์์ ๋์ผํ๊ฒ ์ ๋ฌํ๋ ๋ฐฉ์์ผ๋ก ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ๋ฐฉ์์ด๋ค.

### ๐ ํจ์๋ฅผ ์ ์ ํ ๋ default value parameter๋ฅผ non-default value parameter ์์ ์ ์ ํ๋ฉด ์ ๋๋ ์ด์

๐ก ํ๋ผ๋ฏธํฐ๋ฅผ ์ ์ํ๋ ์์ ์์ด ๋ฌด์์๋ก ์์ฑ ์ ํจ์๋ ์ด๋ค ํ๋ผ๋ฏธํฐ์ ์ด๋ค ๊ฐ์ ๋ฐ์์ผ ๋ ์ง ์ ํ  ์ ์๊ธฐ ๋๋ฌธ

โ๏ธ ๊ฐ๋ณ ์ธ์๋ฅผ ์ฌ์ฉํ  ๋ ์๋ ฅ ์์
1. positional parameter (arg1, arg2)
2. optional parameter (arg=none)
3. keyword parameter (arg="value")
4. list parameter (arg=[])
5. keyword-only (*arg)
6. var-keyword parameter (**arg)

### ๐ ๋ค์ ์์ ์ ์ค๋ฅ๋ฅผ ํด๊ฒฐํด ๋ณด์!

def func_param_with_var_args(name, *args, age):
print("name=",end=""), print(name)
print("args=",end=""), print(args)
print("age=",end=""), print(age)

func_param_with_var_args("์ ์ฐ์ฑ", "01012341234", "seoul", 20)

๐ก ์์์ ์ค๋ฅ๊ฐ ๋ฐ์ ํ ์ด์ ๋ ์์์ด๋ค. *args ์ age์ ์์๋ฅผ ๋ฐ๊ฟ์ผํ๋ค.

def func_param_with_var_args(name,age,*args,):
print("name=",end=""), print(name)
print("args=",end=""), print(args)
print("age=",end=""), print(age)

func_param_with_var_args("์ ์ฐ์ฑ", "01012341234", "seoul", 20)
I Love Pizza, ๋๋ง์ ํ ํ์ผ๋ก ํ์กฐ๊ฐ์ฉ ๋ง์ถฐ๊ฐ๋ ์ค