1#!/usr/bin/python
2
3import sys
4
5for args in sys.argv:
6 print(args)
7
8"""
9If you were to call the program with subsequent arguments, the output
10will be of the following
11Call:
12python3 sys.py homie no
13
14Output:
15sys.py
16homie
17no
18"""
1#*args and **kwargs are normally used as arguments when calling the function.
2
3#*args returns as tuple and **kwargs returns as dictionary.
4
5#*args and **kwargs let you write functions with variable number of arguments in python.
6
7def func(required,*args,**kwargs):
8 return f"{required} {args} {kwargs}"
9
10func("Nagendra",5,32,2,1,23,) #output == 'Nagendra (5, 32, 2, 1, 23) {}'
11func("Nagendra",5,32,2,1,23,key1="55",key2="75") #output == "Nagendra (5, 32, 2, 1, 23) {'key1': '55', 'key2': '75'}"
12
13#Very understable example of args.
14#Given n number of arguments in a function calculate its average
15def average(*args):
16 '''
17 As we already know *args means collection of values in a tuple.
18 INPUT: arguments are given. example average(4,10,)
19 OUTPUT: average of two numbers (4+10)/2 == 14
20 '''
21 return sum(args)/len(args)
22
23average(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15) #output == 8.0
1def some_function (self, a, b, c, d = None, e = None, f = None, g = None, h = None):
2 #code
3