This section describes how to design and pass Multiple Parameter subfunctions.
In Section 2.3, we discussed how to design a sub-function with parameters. Now we will study how to transmit the design methods of two or more parameters.
Why do functions require parameters? In fact, the reason is very simple, that is, to give more data to the sub-function for processing. It seems too stretched to pass only one parameter to the sub-function, similar to C, Python can be used to design multiple parameters for subfunctions, but you do not need to specify the parameter type. This is very nice! Well, let's look at the syntax structure, as shown below.
[Python]
Def func (arg1, arg2 ,....):
(Tab) statment1
(Tab) statment2
(Tab) statment3
Etc.
Def func (arg1, arg2 ,....):
(Tab) statment1
(Tab) statment2
(Tab) statment3
Etc. Example. [Python] view plaincopyprint? # Define the area function area
Def area (width, height ):
Z = width * height
Print (z)
# Define the main function
Def main ():
W = int (raw_input ("plz input width "))
H = int (raw_input ("plz input heighnt "))
# Calling the subfunction area
Area (w, h)
# The Program Execution entry is also called the main function.
Main ()
# Define the area function area
Def area (width, height ):
Z = width * height
Print (z)
# Define the main function
Def main ():
W = int (raw_input ("plz input width "))
H = int (raw_input ("plz input heighnt "))
# Calling the subfunction area
Area (w, h)
# The Program Execution entry is also called the main function.
Shows the main () program execution process.
The result is as follows:
[Python]
Plz input width12
Plz input heighnt13
156
Plz input width12
Plz input heighnt13
156