Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

star operator python

In a function call the '*' unpacks data structure of tuple or list into positional or keyword arguments to be received by function definition.

In a function call the '**' unpacks data structure of dictionary into positional or keyword arguments to be received by function definition.

In a function definition the '*' packs positional arguments into a tuple.

In a function definition the '**' packs keyword arguments into a dictionary.

Comment

star operator python

In function construction         In function call
=======================================================================
          |  def f(*args):                 |  def f(a, b):
*args     |      for arg in args:          |      return a + b
          |          print(arg)            |  args = (1, 2)
          |  f(1, 2)                       |  f(*args)
----------|--------------------------------|---------------------------
          |  def f(a, b):                  |  def f(a, b):
**kwargs  |      return a + b              |      return a + b
          |  def g(**kwargs):              |  kwargs = dict(a=1, b=2)
          |      return f(**kwargs)        |  f(**kwargs)
          |  g(a=1, b=2)                   |
-----------------------------------------------------------------------
Comment

PREVIOUS NEXT
Code Example
Python :: python oprators 
Python :: drop duplicate rows pandas except nan 
Python :: python ignore unicodedecodeerror 
Python :: how to write multi line lambda in python 
Python :: discord.py get guild member list 
Python :: json.dumps no spaces 
Python :: colab pip 
Python :: python selenium clear input 
Python :: plt.xticks 
Python :: pd get non-numeric columns 
Python :: import matplotlib plt 
Python :: install lz4 python 3 
Python :: tkinter frame inside frame 
Python :: python random real 
Python :: python check if exe is running 
Python :: python zip extract directory 
Python :: print % in python 
Python :: how to shutdown a windows 10 computer using python 
Python :: remove empty lines from file python 
Python :: Issue Pandas TypeError: no numeric data to plot 
Python :: password text in entry in tkinter 
Python :: dataframe get row by name 
Python :: how to use with open 
Python :: make dataframe index a column 
Python :: sklearn train_test_split 
Python :: tkinter open new window 
Python :: python numba 
Python :: how to print x in python 
Python :: how to add three conditions in np.where in pandas dataframe 
Python :: django models using Value 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =