*args, **kwargs parameter group

Source: Internet
Author: User

 ' 
def Test (*args): # *AGRS receives n positional arguments, cannot accept keyword arguments, conversions Cheng Yuanju
Print (args)

Test (1,2,3,4,5,6)
Test (*[ 1,2,4,5,5] # arge=tuple ([1,2,3,4,5])

def test1 (X,*args):
Print (x)
Print (args)

def test2 (**kwa RGS): #接受n个关键字参数, convert n keyword arguments to dictionary
Print (Kwargs)
Print (kwargs["name"])
Print (kwargs[' age ')
Print ( kwargs["Sex"])

Test2 (name= "Alex", age=8,sex= ' F ')
#test2 (**{' name ': ' Alex ', "Age": 8})

def test3 ( Name,**kwargs):
Print (name)
Print (Kwargs)

Test3 (' Alex ', age=18,sex= "M") #必须是关键参数, not directly a string test3 (' Alex ', ' sddd ', sex= "M")

def test4 (Name,age=18,**kwargs): #默认参数写到后面? No, the parameter group is going to the rear
print (name)
Print (age)
Print (Kwargs)

Test4 ("Alex", sex= ' m ', hobby= ' Tesla ', age=3) #默认 Age can be put in the back? Yes, can be positional parameter, can keyword parameter
' '
' '
def test5 (Name,age=18,*args,**kwargs):
Print (name)
Print (age)
Prin T (args)
Print (Kwargs)

Test5 ("Alex", sex= ' m ', hobby= ' Tesla ')
'

*args, **kwargs parameter groups

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.