
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
What does ** (double star) and * (star) do for parameters in Python?
In Python function, an argument with single asterisk (star) prefixed to it helps in receiving variable number of argument from calling environment
>>> def function(*arg): for i in arg: print (i) >>> function(1,2,3,4,5) 1 2 3 4 5
Argument with double asterisks (stars) is used in function definition when variable number of keyword arguments have to be passed to a function
>>> def function(**arg): for i in arg: print (i,arg[i]) >>> function(a=1, b=2, c=3, d=4) a 1 b 2 c 3 d 4
In Python 3, it is possible to define a variable with asterisk in assignment statement to enable extended unpacking of iterables.
>>> a,*b=[1,2,3,4] >>> a 1 >>> b [2, 3, 4] >>> a,*b,c=[1,2,3,4] >>> a 1 >>> b [2, 3] >>> c 4
- Related Articles
- What does the Double Star operator mean in Python?
- What does the Star operator mean in Python?
- What does double underscore prefix do in Python variables?
- Check For Star Graph
- Double-Star Connection of Transformers – Three-to-Six Phase Transformation
- What is Star Schema?
- What is Pole Star?
- How does a Planet differ from a Star?
- C Program for Arrow Star Pattern
- How to unpack using star expression in Python?
- Star-Star Connection of Transformer | Three - Phase Transformer Connection
- Why importing star is a bad idea in python
- Program to find center of star graph in Python
- What is Star Network Topology in Computer Network?
- Python Program to Print an Inverted Star Pattern

Advertisements