Example analysis of python function parameter usage

Source: Internet
Author: User
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.

  • 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.