How to Check if x is Equal to y or z in Python?

Estimated read time 1 min read

To check if a variable x is equal to either y or z in Python, you can use the logical OR operator (or) in an if statement. Here’s an example:

x = 10
y = 5
z = 10

if x == y or x == z:
    print("x is equal to y or z.")
else:
    print("x is not equal to y or z.")

In this example, the if statement checks if x is equal to either y or z. The logical OR operator (or) is used to combine the two conditions. If either condition is true, the code inside the if block is executed and the message “x is equal to y or z” is printed. If both conditions are false, the code inside the else block is executed and the message “x is not equal to y or z” is printed.

You can modify the values of x, y, and z to match your specific use case.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply