[英]Why python does not raise NameError
Consider this simple case: 考虑这个简单的情况:
i = 10
if i != id:
print i
As id
is not defined here so i was assuming to get NameError: name 'id' is not defined
but it does not raise any. 因为
id
没有在这里定义所以我假设得到NameError: name 'id' is not defined
但它没有引发任何。
But in this case: 但在这种情况下:
id = 10
if i != id:
print i
It actually raised a NameError
exception for i
. 它实际上为
i
引发了一个NameError
异常。 So can anyone explain it to me this behaviour? 所以有人能解释一下这种行为吗?
id
is a built-in function, so it actually is defined. id
是一个内置函数,所以实际上是定义的。 Use another name for your variable. 为变量使用其他名称。
Here is a list of all built-in functions . 以下是所有内置函数的列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.