1import sys
2print("This is the name of the script:", sys.argv[0])
3print("Number of arguments:", len(sys.argv))
4print("The arguments are:" , str(sys.argv))
5
6#Example output
7#This is the name of the script: sysargv.py
8#Number of arguments in: 3
9#The arguments are: ['sysargv.py', 'arg1', 'arg2']
1#argv in python
2
3
4import sys
5
6print 'Number of arguments:', len(sys.argv), 'arguments.'
7print 'Argument List:', str(sys.argv)
8
9#command in cmd :
10$ python test.py arg1 arg2 arg3
11
12# producing following result :
13Number of arguments: 4 arguments.
14Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
1# arguments
2def test_var_args(f_arg, *argv):
3 print("first normal arg:", f_arg)
4 for arg in argv:
5 print("another arg through *argv :", arg)
6
7test_var_args('yasoob','python','eggs','test')
8
9# keywork arguments
10def test_var_kwargs(f_arg, **kwargs):
11 print(f_arg)
12 for (key, item) in kwargs.items():
13 print("Keyword: ", key)
14 print("Value: ", item)
15
16test_var_kwargs('yasoob', x = 12)
17