新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python參數(shù)解包的實(shí)現(xiàn)
在參數(shù)的使用方法中,還有一種解包的情況是需要我們掌握的。比如,將列表或者字典的值轉(zhuǎn)換為函數(shù)的參數(shù),就需要用到參數(shù)解包的功能。

成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供香洲網(wǎng)站建設(shè)、香洲做網(wǎng)站、香洲網(wǎng)站設(shè)計(jì)、香洲網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、香洲企業(yè)網(wǎng)站模板建站服務(wù),10年香洲做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
1、* 操作符 可以用來解包列表和元組。
>>> list(range(3, 6)) # normal call with separate arguments [3, 4, 5] >>> args = [3, 6] >>> list(range(*args)) # call with arguments unpacked from a list [3, 4, 5]
2、** 操作符 可以用來解包字典。
>>> def parrot(voltage, state='a stiff', action='voom'):
... print("-- This parrot wouldn't", action, end=' ')
... print("if you put", voltage, "volts through it.", end=' ')
... print("E's", state, "!")
...
>>> d = {"voltage": "four million", "state": "bleedin' demised", "action": "VOOM"}
>>> parrot(**d)以上就是python參數(shù)解包的實(shí)現(xiàn),希望能對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
網(wǎng)站題目:創(chuàng)新互聯(lián)Python教程:python參數(shù)解包的實(shí)現(xiàn)
當(dāng)前地址:http://m.fisionsoft.com.cn/article/dpcsgei.html


咨詢
建站咨詢
