Python function parameter usage instance analysis, python function instance analysis
This example describes how to use python function parameters. Share it with you for your reference. The details are as follows:
Function parameters:
The parameters obtained by the function are the values you provide to the function, so that the function can use these values to do something. These parameters are just like variables, except that their values are defined when we call a function, rather than being assigned values in the function itself.
The parameter is specified in the parentheses defined by the function and is separated by commas. When we call a function, we provide the value in the same way. Note the term we used-the parameter name in the function is the form parameter and the value you provide to the function call is called the real parameter.
Use 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 = 7 printMax (x, y) # give variables as arguments
The running result is as follows:
4 is maximum
7 is maximum
Working principle:
Here, we define a function called printMax, which requires two parameters, a and B. We use the if... else statement to find a large number of the two and print a large number.
In the use of the first printMax, we directly provide the number, that is, the real parameter, to the function. In the second use, we use variables to call functions. PrintMax (x, y) assigns the value of real parameter x to the form parameter a, and the value of real parameter y to the form parameter B. In the two calls, the printMax function works exactly the same.
I hope this article will help you with Python programming.