![图片[1]-python判断键在不在字典里-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5e732516636b0614.jpg)
python3 中采用 in 方法
#判断字典中某个键是否存在
arr={"int":"整数","float":"浮点","str":"字符串","list":"列表","tuple":"元组","dict":"字典","set":"集合"}
#使用in方法
if"int"inarr:
print("存在")
if"float"inarr.keys():
print("存在")
#判断键不存在
if"floats"notinarr:
print("不存在")
if"floats"notinarr:
print("不存在")
#判断字典中某个键是否存在
arr={"int":"整数","float":"浮点","str":"字符串","list":"列表","tuple":"元组","dict":"字典","set":"集合"}
#使用自带的has_key()
if(arr.has_key("int")):
print("存在")原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END

















































暂无评论内容