def?exchange(d):
景泰ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
res?=?dict((v,k)?for?k,v?in?d.items())
print(res)
print(d)
一行代碼完成交換的,按你的需求定義了一個(gè)函數(shù)
應(yīng)該是用大括號(hào)的 # create a mapping of state to abbreviationstates = { 'Oregon': 'OR', 'Florida': 'FL', 'California': 'CA', 'New York': 'NY', 'Michigan': 'MI'}# create a basic set of states and some cities in themcities = { 'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}
#函數(shù)傳遞參數(shù)
def func_args( ?*vartuple ):
args = []
#任何傳入的參數(shù)都加入列表
for var in vartuple:
args.append(var)
return args
a = func_args("123","abc","ABC","000")
print(a)
#?-*-?coding:utf-8?-*-
#py3
'''
python?字典當(dāng)作函數(shù)參數(shù),及遍歷
'''
def?f(di):??//定義函數(shù)
for?key?in?di:?????//兩種方式遍歷字典
print(key,':',di[key])
for?key,value?in?di.items():
print(key,'-',value)??????
dic={1:'a',2:3,3:'test',4:100}
f(dic)