m1=[]
m2={}
m3=()
m4={"name":1,"age":2}
#也可用if not m1:print("m1不是列表")
if m1:
print("m1不是列表")
else:
print(m1)
print("m1是空列表")
if m2:
print("m2不是字典")
else:
print("m2是空字典")
if m3:
print("m3不是元组")
else:
print("m3是空元组")
#判断字典是否存在某个key
if('age' in m4.keys()):
print("m4包含age")
else:
print("m4不包含age")
python3判断字典、列表、元组为空以及字典是否存在某个key的方法
猜你喜欢
转载自blog.csdn.net/weixin_38383877/article/details/83536908
今日推荐
周排行