主要是为了记录python中的if xx: 与if xx is not None:细节问题。
if xx is not None: = if xx != None
if xx: = if xx != None and xx != " " and xx != False and xx != 0 and xx != [] and xx != {} and....
xx is not None 只是判断xx是不是 None 类型,如果不是None 类型,则返回True。
假设xx==0, 那么 if xx 返回值为 False,但是 xx is not None 返回值为True。
可以看出两者还是很不一样的!
if xx: 与if xx is not None:
最新推荐文章于 2023-06-06 10:58:57 发布