我对==
和is
的用法感到困惑。你知道吗
default_netrc = file is None
if file is None:
try:
file = os.path.join(os.environ['HOME'], ".netrc")
except KeyError:
raise IOError("Could not find .netrc: $HOME is not set")
这是代码快照。你知道吗
这条线default_netrc = file is None
等于default_netrc = file == None
吗?你知道吗
与None
相比,我们应该使用is
还是==
?你知道吗
a is b
返回id(a)==id(b)
,如果标签指向同一对象,则为真。a==b
如果a和b所指向的(可能不同的)对象在被比较的对象所定义的方式上是等价的,则返回true。你知道吗相关问题 更多 >
编程相关推荐