Python 字典(Dictionary) has_key()方法

Python 教程 · 2019-02-03 07:43:16

描述

Python 字典(Dictionary) has_key() 函数用于判断键是否存在于字典中,如果键在字典dict里返回true,否则返回false。

语法

has_key()方法语法:

dict.has_key(key)

参数

  • key -- 要在字典中查找的键。

返回值

如果键在字典里返回true,否则返回false。

实例

以下实例展示了 has_key()函数的使用方法:

#!/usr/bin/python

dict = {'Name': 'Zara', 'Age': 7}

print "Value : %s" %  dict.has_key('Age')
print "Value : %s" %  dict.has_key('Sex')

以上实例输出结果为:

Value : True
Value : False

点击查看所有 Python 教程 文章: https://www.codercto.com/courses/l/8.html

查看所有标签

The Art of Computer Programming, Volume 4,  Fascicle 3

The Art of Computer Programming, Volume 4, Fascicle 3

Donald E. Knuth / Addison-Wesley Professional / 2005-08-05 / USD 19.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 4, Fascicle 3》 这本书的介绍吧!

MD5 加密
MD5 加密

MD5 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

html转js在线工具
html转js在线工具

html转js在线工具