Using Function Parameters
Example 7.2. Using Function Parameters
#!/usr/bin/python
# Filename: func_param.py def printMax(a, b):
if a > b:
print a, 'is maximum' else:
print b, 'is maximum' printMax(3, 4) # directly give literal values x = 5
y = 7
printMax(x, y) # give variables as arguments
Output
$ python func_param.py
4 is maximum
7 is maximum
How It Works
Here, we define a function called
printMax where we take two parameters called
a and
b. We find out the greater number using a simple
if..else statement and then print the bigger number.
In the first usage of printMax, we directly supply the numbers i.e. arguments. In the second usage, we call the function using variables.printMax(x, y) causes value of argumentx to be assigned to parametera and the value of argumenty assigned to parameterb. The printMax function works the same in both the cases.