#๐Ÿ”’ Syntax clarification

21 messages ยท Page 1 of 1 (latest)

vague streamBOT
#

@brittle drift

Python help channel opened

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.

brittle drift
#

How does the loop while cur: behave

dense schooner
#

Just like any other while loop. While the condition (in this case cur) is True (or evaluates to True), then the loop executes.

brittle drift
#

so the loop only works for cur == True and not other datatypes?

autumn zinc
dense schooner
autumn zinc
#

this is a good explanation

grim light
#

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

brittle drift
grim light
#

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

dense schooner
grim light
#

A str when it is empty etc.

brittle drift
#

Right

#

Thanks

vague streamBOT
#
Python help channel closed

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.