Python _ function parameter transfer

Source: Internet
Author: User

In this example, we will discuss the parameter passing problem of the function.
The python version I use is 3.3.2.

For functions:

             fun(    ==      main()

Information.

The printed information here is:

hello,Hongten

For the following use cases:

  fun(a=1, b=None, c=None, *     (       fun(a=     fun(    ==      main()

When the passing parameters are fun (a = 'one') and fun ('one'), the values are copied to parameter, the effects of all two parameters are the same:

 

Of course, we can also assign values to parameters B, c, and * args.

For example:

  fun(a=1, b=None, c=None, *     (       fun(,1,2,(    ==      main()

In this way, values are assigned to parameters B, c, and args.

Running effect:

one,1,2,(,)

In the preceding column, we cannot bypass the parameters a, B, and c in front of * args to copy * args:

For example:

  fun(a=1, b=None, c=None, *     (       fun(args=(    ==      main()

Running effect:

, line 21,  <module>, line 18, =(

However, for parameters a, B, and c, you can assign values in this way.

For example:

  fun(a=1, b=None, c=None, *     (       fun(c=(), b=2, a=[1,2,3    ==      main()

Running effect:

[1, 2, 3],2,hongten,()

 

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.