Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Using Python 3.4, wondering how does this loop processing?
while SyntaxError: print ("Hi")
It's an infinite loop, how does this while loop running? It's an exception but..?
while
SyntaxError
while True
Exception
Exceptions are just objects unless they're raised - bool(SyntaxError) is True, so your loop is effectively while True:
raise
bool(SyntaxError)
True
while True:
Add a comment
Boolean value of SyntaxError is True.
>>> bool(SyntaxError) True
That is why while loop is going in infinite loop because while SyntaxError: is equivalent to while True: condition.
while SyntaxError:
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
SyntaxErrorclass evaluates truthy in a Boolean context. This is equivalent towhile True, that it's anExceptionis irrelevant.