Python--函數參數類型

來源:互聯網
上載者:User

標籤:ret   字典   color   字元   name   gpo   style   nbsp   關鍵字   

Python 函數參數主要分為3種形式:

     1.位置或關鍵字參數

    2.任意數量的位置參數

    3.任意數量的關鍵字參數

def fun7(a,b,c):    print a,b,cfun7(1,8,9)fun7(a=89,c=70,b=99)fun7(a="soyo",c=100,b="soyosoyo")def fun8(str2,*num):    print "字串為:"+str2    print "數字為:",num    return numq=fun8("soyo5",1,2,6,8)for i in q:    print idef fun9(str3,*num1,**kwargs):    print "str3="+str3    print "元組內的數字為:",num1    print "字典為:",kwargs    return kwargsa1=fun9("soyo100",1,5,9,name="小米",value=88)keys=a1.keys()print keysfor i in keys:    print a1[i]

結果:

1 8 9
89 99 70
soyo soyosoyo 100
字串為:soyo5
數字為: (1, 2, 6, 8)
1
2
6
8
str3=soyo100
元組內的數字為: (1, 5, 9)
字典為: {‘name‘: ‘\xe5\xb0\x8f\xe7\xb1\xb3‘, ‘value‘: 88}
[‘name‘, ‘value‘]
小米
88

Python--函數參數類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.