Skip to content

Instantly share code, notes, and snippets.

@nishidy
Last active March 15, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishidy/be7f0e9b919ea4886e89f44d4a6a0b67 to your computer and use it in GitHub Desktop.
Save nishidy/be7f0e9b919ea4886e89f44d4a6a0b67 to your computer and use it in GitHub Desktop.
Variable length variable / Keyword variable length variable
def func(a,b=10,*c,**d):
print(a,b,c,d)
func(1,20,30,40)
func([1,20,30,40])
func({'a':1,'b':20,'c':30,'d':40})
func(*[1,20,30,40])
func(**{'a':1,'b':20,'c':30,'d':40})
a = {1:10,2:20}
b = {3:30,4:40}
print({**a,**b})
@nishidy
Copy link
Author

nishidy commented Mar 15, 2017

$ python --version
Python 3.5.0
$ python asta.py 
1 20 (30, 40) {}
[1, 20, 30, 40] 10 () {}
{'c': 30, 'b': 20, 'd': 40, 'a': 1} 10 () {}
1 20 (30, 40) {}
1 20 () {'c': 30, 'd': 40}
{1: 10, 2: 20, 3: 30, 4: 40}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment