Python3 function parameters, python3 function parameters

Source: Internet
Author: User

Python3 function parameters, python3 function parameters

1 ## General parameter 2 # def jiafa (a, B): 3 # print (a + B) 4 #5 # jiafa (5, 6) 6 #7 #8 # def xinxi (name, location, sex = 'male'): # The default parameter is 9 # print ('name: % s' % name) 10 # print ('gender: % s' % sex) 11 # print ('hometown: % s' % location) 12 #13 #14 # xinxi ('bob', 'shansi') 15 #16 # variable length parameter 17 # def add (* jiafa): # * followed by a tuple, random name, generally write args (no name parameter) 18 # print (jiafa) 19 # sum = 020 # for I in jiafa: 21 # sum + = i22 # print (sum) 23 # add (, 5) 24 #25 # def informations (** info): # ** use a dictionary later. The name is random. Generally, write kwargs (with naming parameters) 26 #27 # for I in info: # I is the key, info is the value 28 # print ('% s: % s' % (I, info [I]) 29 # informations (name = 'lily', age = 18, sex = 'female ', job = 'deletewoman', location = 'beijinging ') 30 #31 # def test (* a, ** B): 32 # print (a, B) 33 # test ('asd ', 2, 22, ['asd ', 1], (, 5), name = 'bob') 34 35''' 36 about the location of the indefinite length parameter * put agrs on the left, ** put kwargs on the right 37. The default value is 38 to the left of the variable length parameter. The order is keyword parameter, default value parameter, * args, ** kwargs39 '''

 

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.