2.3. VarArgs parameters - JulTob/Python GitHub Wiki

Sometimes you might want to define a function that can take any number of parameters, i.e. variable number of arguments, this can be achieved by using the stars (save as function_varargs.py ):

def total(a=5, *numbers, **phonebook):
  print('a', a)

  #iterate through all the items in tuple
  for single_item in numbers:
    print('single_item', single_item)

  #iterate through all the items in dictionary
  for first_part, second_part in phonebook.items():
    print(first_part,second_part)


'''
total(10,1,2,3,Jack=1123,John=2231,Inge=1560)

>>>
a 10
single_item 1
single_item 2
single_item 3
Inge 1560
John 2231
Jack 1123
'''
import sys

print('The command line arguments are:')
for i in sys.argv:
  print(i)

print('\n\nThe PYTHONPATH is', sys.path, '\n')