Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OR in Python for a yes/no?

Tags:

python

I'm wanting to have a "y/n" in Python, which i've successfully done, but I want the user to be able to input a "y" or a "Y" and it accepts both.

Here's a short if statement

if yn == "y":
    break

I'm wanting to make it be something like this

if yn == "y" || "Y":
    break

But "||" is the OR operator in Java. I don't know what the OR operator is in Python or if I could even use it for something like this. Any help?

like image 537
mwstray Avatar asked Feb 13 '26 12:02

mwstray


1 Answers

You're looking for

if yn in ("y", "Y"):

Or better:

if yn.lower() == 'y':
like image 58
jamylak Avatar answered Feb 15 '26 01:02

jamylak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!