Python > Class > ์์ฑ์
ย ํ์ด์ฌ์์๋ ์ธ์คํด์ค ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋ ์ด๊ธฐํ ์์ ์ ์ํด ์์ฑ์ ๋ฉ์๋๋ฅผ, ๋ฉ๋ชจ๋ฆฌ ํด์ ๋ฑ์ ์ข ๋ฃ ์์ ์ ์ํด ์๋ฉธ์ ๋ฉ์๋๋ฅผ ์ง์ํ๊ณ ์๋ค. ์์ฑ์ ๋ฉ์๋๋ ์ธ์คํด์ค ๊ฐ์ฒด๊ฐ ์์ฑ๋ ๋ ์๋์ผ๋ก ํธ์ถ๋๋ฉฐ, ์๋ฉธ์ ๋ฉ์๋๋ ์ธ์คํด์ค ๊ฐ์ฒด์ ๋ ํผ๋ฐ์ค ์นด์ดํฐ๊ฐย โ0โฒ์ด ๋ ๋ ํธ์ถ๋๋ค.
__init__(self, *args, **kwargs)
# ์ฐธ๊ณ :ย https://www.agiliq.com/blog/2012/06/understanding-args-and-kwargs/
ย What does *args do in a function definition? It recieves a tuple containing the positional arguments beyond the formal parameter list. So, args is a tuple. Since โargsโ is a tuple, we could iterate over it.
ย Letโs use ** from inside the function call. For this we want a dictionary. Remember, while using * in the function call, we required a list/tuple. For using ** in the function call, we require a dictionary.
ย Whatย **ย did while being used in a function call? It unpacked the dictionary used with it, and passed the items in the dictionary as keyword arguments to the function.
ย So, ** unpacks the dictionary i.e the key values pairs in the dictionary as keyword arguments and these are sent as keyword arguments to the function being called. *ย unpacks a list/tuple i.e the values in the list as positional arguments and these are sent as positional arguments to the function being called.
ย What does * * kwargs mean when used in a function definition? With **kwargs in the function definition, kwargs receives a dictionary containing all the keyword arguments beyond the formal parameter list. Remember kwargs will be a dictionary.














