[Python] 가변인자, 패킹, 언패킹

ICONFINDER
>>> args = 1, 2, 3
>>> args
(1, 2, 3)
>>> a, b, c = args
>>> a
1
>>> b
2
>>> c
3
>>> x, *new_args = args
>>> x
1
>>> new_args
[2, 3]
def refresh_connection(conn, *args, **kwargs):
conn.close()
return make_connection(*args, **kwargs)
def func(*args, **kwargs):
return print(*args, **kwargs)
>>> def func(*args, **kwargs):
... print(args[0])
... print(args[1])
... print(kwargs['x'])
>>> func(1, x='x')
args 0 index 1
kwargs 'x' element x
>>> func(1, 2, 3, x='x', y='y', z='z')
args 0 index 1
kwargs 'x' element x
>>> func(*(1,2,3), **{'x':'x', 'y':'y', 'z':'z'})
args 0 index 1
kwargs 'x' element x

--

--

Blog https://chrisjune.dev Work for www.29cm.co.kr

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store