
- 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 use variable-length arguments in a function in Python?
In Python, the single-asterisk form of *args can be used as a parameter to send a non-keyworded variable-length argument list to functions. It is seen that the asterisk (*) is important here, and along with the word args it means there is a variable length list of non-keyworded arguments.
Example
def multiply(*args): y = 1 for num in args: y *= num print(y) multiply(3, 7) multiply(9, 8) multiply(3, 4, 7) multiply(5, 6, 10, 8)
Output
21 72 84 2400
- Related Questions & Answers
- Variable-length arguments in Python
- How to use variable number of arguments to function in JavaScript?
- Demonstrating variable-length arguments in Java
- Variable length arguments for Macros in C
- How to use a global variable in a Python function?
- How to use unlimited arguments in a JavaScript function?
- Command Line and Variable Arguments in Python?
- How to pass arguments by reference in a Python function?
- How to pass arguments by value in Python function?
- How to pass arguments by reference in Python function?
- Variable Arguments (Varargs) in C#
- How to Count Variable Numbers of Arguments in C?
- Variable number of arguments in C++
- What are variable arguments in java?
- How to change all the function arguments to lowercase in Python?
Advertisements