Python parameters code example
Example 1: pass argument to a py file
import sys
def hello(a,b):
print "hello and that's your sum:", a + b
if __name__ == "__main__":
a = int(sys.argv[1])
b = int(sys.argv[2])
hello(a, b)
Example 2: python read arguments
import sys
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
Example 3: read argument from terminal
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
Example 4: python arguments
import sys
print ("the script has the name %s" % (sys.argv[0])
Example 5: how to make a function in python
def test_function(argument1,argument2,argument3) :
print(argument1)
print(argument2)
print(argument3)
test_function('Hello','World','!')
'''
Hello
World
!
'''
Example 6: how to add a function in python
def new_function():
print("Hello World!")
new_function()