Python variable list of parameters

Source: Internet
Author: User

The number of parameters in a general computer language cannot be changed, but the number of arguments in Python can be changed. This is achieved primarily through *arg and **arg in formal parameters, and the following rules must be observed with variable arguments:

1. Position parameter must appear before this *arg parameter

2, *arg must appear before **arg, after *arg this and **arg before the parameter must be the keyword parameter

3,**arg parameters can not have any parameters, in addition.

4, *arg after collecting positional parameters, the non-keyword parameter is a meta-ancestor, and **arg collects the keyword parameter as a dictionary.

def Testone (x,*xx,y=21,z=2, * *yy)    :print(x,y,z,xx,yy)if__ name__= ='__main__':    testone (1, 2,4, z=22, y=22, k1=0)

Results: 1 (2, 4) {' K1 ': 0, ' K2 ': 1}

Splitting of parameter lists
arg=[1,3,5]print(*arg)

Results: 1 3 5

Python variable list of parameters

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.