

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to call a function with argument list in Python?
def baz1(foo, *args):
The * next to args means "take the rest of the parameters given and put them in a list called args".
In the line:
foo(*args)
The * next to args here means "take this list called args and 'unwrap' it into the rest of the parameters.
in foo2, the list is passed explicitly, but in both wrappers args contains the list [1,2,3].
def baz1(foo, *args): # with star foo(*args) def baz2(foo, args): # without star foo(*args) def foo2(x, y, z): print x+y+z baz1(foo2, 2, 3, 4) baz2(foo2, [2, 3, 4])
OUTPUT
9 9
- Related Questions & Answers
- How to pass Python function as a function argument?
- How to pass a dictionary as argument in Python function?
- How to call jQuery function with JavaScript function?
- How to call a function in JavaScript?
- How to call a function of a module from a string with the function's name in Python?
- How to call a function of a module from a string with the function's name in Python?
- How to call a jQuery library function?
- How to call a Java function inside JavaScript Function?
- Call a function with onclick() – JavaScript?
- How to call a JavaScript function in HTML?
- How to call a JavaScript function on click?
- How to call a JavaScript function from C++?
- How to Call a Lua function from C?
- How to call a function after a delay in Kotlin?
- How we can call Python function from MATLAB?
Advertisements