Python learning basics (learning Python) -- 2.3.1 Python parameter passing Function Design

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.