黄色电影一区二区,韩国少妇自慰A片免费看,精品人妻少妇一级毛片免费蜜桃AV按摩师 ,超碰 香蕉

Python 字典 Dictionary get()方法

Python 字典 Dictionary get()方法

Python 字典 DictionaryPython 字典 Dictionary

Python 字典(Dictionary) get() 函數(shù)返回指定鍵的值。

 

語法

get()方法語法:

dict.get(key, default=None)

 

參數(shù)

  • key -- 字典中要查找的鍵。
  • default -- 如果指定鍵的值不存在時,返回該默認值。

 

返回值

返回指定鍵的值,如果鍵不在字典中返回默認值 None 或者設置的默認值。

 

實例

以下實例展示了 get()函數(shù)的使用方法:

#!/usr/bin/python

dict = {'Name': 'codebaoku', 'Age': 27}

print "Value : %s" %  dict.get('Age')
print "Value : %s" %  dict.get('Sex', "Not Available")    

以上實例輸出結(jié)果為:

Value : 27
Value : Not Available

Python 字典 DictionaryPython 字典 Dictionary

下一節(jié):Python 字典(Dictionary) has_key()方法

Python 教程

相關文章