Aamir Rind
Aamir Rind

Reputation: 39689

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.

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

Answers (1)

Fabian
Fabian

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

Related Questions