Python3 函數參數,python3函數參數

來源:互聯網
上載者:User

Python3 函數參數,python3函數參數

 1 # # 常規參數 2 # def jiafa(a,b): 3 #     print(a+b) 4 #  5 # jiafa(5,6) 6 #  7 #  8 # def xinxi(name,location,sex='male'):    # 預設參數在其他參數的後面 9 #     print('姓名:%s'%name)10 #     print('性別:%s'%sex)11 #     print('故鄉:%s'%location)12 # 13 # 14 # xinxi('bob','shanxi')15 # 16 # # 可變長參數17 # def add(*jiafa):    # *之後跟一個元組,名字隨意,一般寫args(無具名引數)18 #     print(jiafa)19 #     sum = 020 #     for i in jiafa:21 #         sum += i22 #     print(sum)23 # add(5,5,5)24 # 25 # def informations(**info):   # **之後跟一個字典,名字隨意,一般寫kwargs(有具名引數)26 # 27 #     for i in info:  # i是鍵,info是值28 #         print('%s:%s'%(i,info[i]))29 # informations(name = 'Lily',age = 18,sex = 'female',job = 'policewoman',location ='beijing')30 # 31 # def test(*a,**b):32 #     print(a,b)33 # test('asd',2,22,['asd',1],(1,2,3,4,5),name = 'bob')34 35 '''36 關於不定長參數的位置 *agrs 放在左邊, **kwargs 放在右邊37 預設值加不定長參數的左邊38 順序:關鍵字參數,預設值參數,*args,**kwargs39 '''

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.