This example describes the python function parameter usage. Share to everyone for your reference. Specific as follows:
Function parameters:
The arguments that the function takes are the values that you provide to the function so that the function can do something with these values. These parameters are like variables, except that their values are defined when we call the function, not within the function itself.
Parameters are specified internally within the parentheses of the function definition, separated by commas. When we call a function, we provide the value in the same way. Note that the term we used--the parameter name in the function is a formal parameter, and the value you provide to the function call is called an argument.
Using function Parameters:
#!/usr/bin/python# Filename:func_param.pydef Printmax (A, b): If a > B: print A, ' is maximum ' else: Print B, ' is Maximum ' Printmax (3, 4) # directly give literal Valuesx = 5y = 7printMax (x, y) # give variables as arguments
The results of the operation are as follows:
4 is maximum
7 is maximum
Working principle:
Here, we define a function called Printmax, which requires two parameters, called A and B. We use IF. Else statement to find the larger of the two, and print the larger number.
In the first Printmax use, we directly put the number, that is, the argument, provided to the function. In the second use, we use variables to call the function. Printmax (x, y) assigns the value of the argument x to parameter A, and the value of argument y to parameter B. In two calls, the Printmax function works exactly the same.
Hopefully this article will help you with Python programming.