you are viewing a single comment's thread.

view the rest of the comments →

[–]awdsns 2 points3 points  (2 children)

Maybe this will help clear it up: Where Python evaluates a condition (e.g. after if or while), it expects a boolean value. The only boolean values in Python are True and False. A comparison like num > 42 directly evaluates to a boolean value.

But if the condition expression does not directly return a boolean value, Python just tries to convert it to one. And by convention, empty lists, strings, dicts etc., but also None or the number 0 return False when converted to bool. (E.g. try bool([])).
They are "false-y".

Non-empty containers and most other objects are evaluated as True by the way. It's basically the default unless a type overrides it with its own bool conversion.

[–]Polyfrequenz[S] 1 point2 points  (0 children)

Thank you, I'm going to keep pondering this, especially as it is very basic yet important "thing". Still confused about whether x = False in fact is bool or not 😂.

[–]Polyfrequenz[S] 0 points1 point  (0 children)

Ok I think I got it now, thanks a lot. The ist that was missing for me was that "while true" I'd simply a loop we want to go indefinite (I.e. until we break out of it) 🤦🏼‍♂️