#๐ Syntax clarification
21 messages ยท Page 1 of 1 (latest)
@brittle drift
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
How does the loop while cur: behave
Just like any other while loop. While the condition (in this case cur) is True (or evaluates to True), then the loop executes.
so the loop only works for cur == True and not other datatypes?
Don't understand. Any data type. For example an integer will evaluate to False if it is zero, True otherwise. An empty string or list will evaluate to False, True otherwise.
this is a good explanation
Just imagine that Python will always translate
if condition:
to
if bool(condition):
You can check what bool(condition) is if you are unsure
Does that make sense? @brittle drift
This makes sense
I was wondering how an individual element - cur, would return a bool like how any condition does
Because it is simply cast to a bool with bool()
And the rule on when this evaluates to True or False depends per class
ints and floats evaluate to False for 0 and 0.0
It does not have to be a Bool. It only has to be interpreted as a Bool.
A str when it is empty etc.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.