之间&QUOT区别;如果x"和"如果x不是无" [英] Difference between "if x" and "if x is not None"
本文介绍了之间&QUOT区别;如果x"和"如果x不是无"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看来,如果x是几乎像短手长如果x不是无语法。他们是功能相同,还是有情况下,为第X两个将评估不同的给定值?
It appears that "if x" is almost like short-hand for the longer "if x is not None" syntax. Are they functionally identical or are there cases where for a given value of x the two would evaluate differently?
我将承担行为,也应该是不同的Python实现相同的 - 但如果有细微的差别将是巨大知道
I would assume the behavior should also be identical across Python implementations - but if there are subtle differences it would be great to know.
推荐答案
在下列情况下:
test = False
test = ""
test = 0
test = 0.0
test = []
test = ()
test = {}
test = set()
在如果
测试将有所不同:
if test: #False
if test is not None: #True
这篇关于之间&QUOT区别;如果x"和"如果x不是无"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文