import sys
print ("the script has the name %s" % (sys.argv[0])
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--arg1')
parser.add_argument('--arg2')
args = parser.parse_args()
print(args.arg1)
print(args.arg2)
my_dict = {'arg1': args.arg1, 'arg2': args.arg2}
print(my_dict)
def calculate(n, **kwargs):
n += kwargs["add"]
n *= kwargs["multiply"]
return n
print(calculate(3, add=3, multiply=5)) # (3+3)*5 = 30
#in python, arguments can be used using keywords
#the format is:
def function(arg,kwarg='default'):
return [arg,kwarg]
complex(real=3, imag=5)
complex(**{'real': 3, 'imag': 5})
def fn(*, a): # only keyword arguments
print(a)
# fn(1) # error
fn(a=1)
# function with 2 keyword arguments
def student(name, age):
print('Student Details:', name, age)
# default function call
student('Jessa', 14)
# both keyword arguments
student(name='Jon', age=12)
# 1 positional and 1 keyword
student('Donald', age=13)