Advertisement
eeperry

Unpack list, tuple, and dict as args for function

Oct 8th, 2013
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. You can unpack a tuple or a list into positional arguments using a star.
  2.  
  3. def add(a, b, c):
  4.     print(a, b, c)
  5.  
  6. x = (1, 2, 3)
  7. add(*x)
  8. Similarly, you can use double star to unpack a dict into keyword arguments.
  9.  
  10. x = { 'a': 3, 'b': 1, 'c': 2 }
  11. add(**x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement