2 ms·
That's not right, #5 is dependent on what True is defined to: True = 0 def a(): a = True if a: return True return F
by bjourne 12y ago
That's not right, #5 is dependent on what True is defined to:
True = 0
def a():
a = True
if a:
return True
return False
print a()
There are likely similar subtleties with the other examples, but I don't know the Python spec well enough to see them. You asked why the Python compiler didn't optimize these snippets more and that is the answer.
- TheLoneWolfling 12y ago>>> True = False SyntaxError: can't assign to keyword ...
- bjourne 12y agoThe examples are for Python 2, not 3. But it's blatantly obvious that you are more interested in "not being wrong" than discussing Python's compiler so I'll stop here.