Learn Python Easy Way

Thursday, August 13, 2015

expand list to function arguments

http://stackoverflow.com/questions/7745952/python-expand-list-to-function-arguments

Note: A list is not expanded as arguments by itself.

def a(b,c):
    print(b)

d = [2,3]
a(d) : Will not work because the given list is not expanded.

a(*d) will work: see https://docs.python.org/2/tutorial/controlflow.html#unpacking-argument-lists
Posted by Gopal Singh at 4:34 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2017 (13)
    • ►  September (4)
    • ►  August (6)
    • ►  July (3)
  • ►  2016 (62)
    • ►  August (1)
    • ►  June (8)
    • ►  May (11)
    • ►  April (18)
    • ►  March (17)
    • ►  February (5)
    • ►  January (2)
  • ▼  2015 (77)
    • ►  December (8)
    • ►  November (19)
    • ►  October (28)
    • ►  September (2)
    • ▼  August (17)
      • Unusual return of "and" and "or" in Python
      • expand list to function arguments
      • i18n in python
      • git command with [ ]: git -c i18n.logoutputencodin...
      • % in python
      • tuples and list
      • python tuples
      • What is class
      • {} in python class
      • __str__ and __repr__ in python
      • pass statement in python
      • class and object in python
      • argv in python
      • default value of argument in python when no argume...
      • Function in python
      • variable length argument in Python: **kw
      • if __name__ == "__main__" : Usage
    • ►  July (3)
  • ►  2013 (1)
    • ►  October (1)
Simple theme. Powered by Blogger.