Reputation: 39689
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.
But in this case:
id = 10
if i != id:
print i
It actually raised a NameError
exception for i
. So can anyone explain it to me this behaviour?
Upvotes: 1
Views: 187
Reputation: 4348
id
is a built-in function, so it actually is defined. Use another name for your variable.
Here is a list of all built-in functions.
Upvotes: 4