Python function parameter usage instance analysis, python function instance analysis

Source: Internet
Author: User

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.

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.