#๐ I need help
23 messages ยท Page 1 of 1 (latest)
@mellow flare
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.
!or-gotcha
When checking if something is equal to one thing or another, you might think that this is possible:
# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
print("That's a weird favorite fruit to have.")
While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.
So, if you want to check if something is equal to one thing or another, there are two common ways:
# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
print("That's a weird favorite fruit to have.")
# ...or like this.
if favorite_fruit in ('grapefruit', 'lemon'):
print("That's a weird favorite fruit to have.")
this is why ๐
mhhh
you see how the syntax after in is different?
yea
because how your just checking if var3 is falsy (like an empty string, and empty list or tuple or something like that)
thanks so much I tried it and it works
I'm new to programming so i'm still trying to understand basic python
your initial code would read like this to the python interpreter:
if (var1 in var2) or var3:
that's all fine, we've all been there at one point
i think the tutorial was wrong about that ๐
which tutorial
the one i was watching
and welcome to the wonderful world of coding ๐
I've done the most of the things but this wasn't working and i watched a tutorial
ok bye i'll close the thread
tysm @visual fjord
!close
This help channel has been closed. 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.