One - One Code All

Blog Content

python判断字典列表元组为非空

Python   2009-05-02 17:03:18

False,0,'',[],{},()都可以视为假


直接用 if m  或者 if not m 来判断就好。

if m3:
    print("yes")
else:
    print("no")

    
#判断字典是否存在某个key    
if('age' in m4.keys()):
    print("m4包含age")
else:
    print("m4不包含age")



上一篇:python异常处理try-except Exception as e
下一篇:mysql数据类型decimal类型详解

The minute you think of giving up, think of the reason why you held on so long.