Python Road "third": Python Basics (16)--Function Dynamic parameters

Source: Internet
Author: User

# Dynamic Parameters:
# * 1 star default will pass in the parameters, all placed in the tuple, F1 (*[1 ' 1,22,33,44])
# with 1 stars to handle those values that are passed by default in order

# # #示例
# def func (*args):
# Print (Args,type (args))
# # Execution Mode one
# func (11,33,4,4454,5)
# # Execution Mode two
# li = [11,2,2,3,3,4,54]
# func (*li)
# # Output
# # (one, 4, 4454, 5) <class ' tuple ' >
# # (one, 2, 2, 3, 3, 4, si) <class ' tuple ' >


# #例一
# Dynamic Parameters--Normal pass parameters
# def F1 (*args):
# Print (Args,type (args))
#
# F1 (11,22, "Eric")
# # Output
# (one, one, ' Eric ') <class ' tuple ' >


# #例二
# def F1 (*args): #如果函数定义里面有星号 *,args will have a special function, regardless of the function passed what parameters will be assigned to the args tuple, as the element.
# Print (Args,type (args))
# f1 (11)
# li = [11,22, "Eric"]
# F1 (Li, ' $ ') #传递的参数里面, Li is a tuple, and the value inside the tuple is a list
# # Output
# (one,) <class ' tuple ' >
# ([One, one, ' Eric '], ' <class ') ' tuple ' >


# # Three Examples
# def F1 (*args): #形式参数里面有星号 *, no matter what arguments the function passes, it is assigned to the args tuple as the element.
# Print (Args,type (args))
# li = [11,22, "Eric", ' 33 ',]
# f1 (LI) #不加星号 *, is to insert the entire list as an element into the tuple
# f1 (*li) #加星号 * is to convert every element in the list into the element of the tuple
# # # Note the difference between the two above.
# li = "Alex"
# f1 (*li) #li是一个字符串的情况, there is * equivalent to a For loop inside, the string is inserted into the tuple.
# # Output
# ([One, one, ' Eric ', ' <class '],) ' Tuple ' >
# # (one, one, ' Eric ', ' <class ') ' tuple ' >
# # (' A ', ' l ', ' e ', ' x ') <class ' tuple ' >

Python Road "third": Python Basics (16)--Function Dynamic 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.