Why Does ‘a ==x or y or z’ Always Evaluate To True?

We know most of you keep wondering- why does ‘a ==x or y or z’ always evaluate to true? So, let us discuss and learn why this happens?

Certainly, different operators in Python are used for performing different operations on variables and values. Most importantly, the operators are just standard symbols that have a specific purpose. == operator is one of those operators.

It is a relational operator that can compare the values and returns False or True as per the given condition. Above all, we can make multiple projects using the == operator of Python. 

And it has been seen that many students make a security system using Python programs during their academic courses. This system gives access to the authorized person only. Let’s dive deep and find out why does ‘a ==x or y or z’ always evaluate to true?

Understanding == operator

Firstly, the program for a security system can easily be built using the Python == operator. But, when the students use the program as:




Hi. Please enter your name: Enna

Access granted

What is this!!! Why does it happen?? As you can see that the access must be granted to only Enna, John, and Ali. But, whatever names we give as inputs, it gives access to all. In other words, even if the statement changes as if “Enna” or “John” or “Ali” == name, still it will show the same result.

Are you facing the same issue? Unable to find the necessary solution? Don’t worry, we have provided the solution to this query with three alternative methods. Moreover, they are too simple to be messed with! So, let’s explore a new concept of Python with ease.

First, let’s understand what is getting executed in the above program!

In certain cases, Python behaves and looks similar to that of natural English. But in this kind of situation (as mentioned in the above program), Python does not take abstracts. 

You might be using the context clues that help you to know whether the “John” and “Ali” are objects or not. Therefore the program logical works to as:

if (name == “Enna”) or (“John”) or (“Ali”)

For Bob, it is equal works as:

if (False) or (“John”) or (“Ali”):

Note: The or operator is selecting the first argument as the positivity truth-value.

That is to say,

if “John”:

As the “John” has the positive truth value, the block of the if statement will be executed. This results in “Access granted” regardless of the given name.

Now, the expression if “Enna” or “John” or “Ali” == name, the value of “Enna” will be true. This also results in the execution of the if block statement.

What is the best solution to the above program?

There are three methods to solve the issue of the above program. Let’s check each of them one by one.

1. Use the “==” operator multiple times

Python users can use the “==” operator multiple times to explicitly check the value of each input.

How to use the “==” operator?




Hi. Please enter your name: Bob

Access denied.




Hi. Please enter your name: Enna

Access granted.

NOTE: The multiple “==” operator might be a slow process as you have to declare each name-value individually. 

2. Using elif condition:

The “elif” refers to else if. This condition allows the users to check the multiple expressions. In the case of FALSE if condition, it analyzes the condition given in the next elif condition. 

That is why we can say that when the conditions are FALSE, then the else body statement will be executed.

How to use the elif condition?




Hi. Please enter your name: Enna

Access granted

Input 2:



Hi. Please enter your name: Bob

Access denied

NOTE: This condition is also considered slow because it will take time to define each name-value individually. Moreover, it makes your program lengthy as it takes unnecessary codes to define each value.

3. Use the “in” operator

The “in” operator in Python uses for checking whether a value exists within the sequence or not. The statement of the “in” operator is evaluated to be TRUE when it finds a variable within the given sequence, otherwise, it results as FALSE.

How to use the “in” operator?




Hi. Please enter your name: Bob

Access denied




Hi. Please enter your name: Enna

Access granted

NOTE: This process considers being much faster and less time-consuming. In the “in” operator, the Python user needs to define the names in the “in” statement, and that it. It will execute the code value and give the result as per the statement. 

Let’s wrap our understanding towards- Why Does ‘a ==x or y or z’ Always Evaluate To True!!

It has been seen that the “==” operator works differently for a different condition. With the “or” logical operator it executes the first condition and considers others as POSITIVE VALUE. That is why you might be facing a similar issue with your code.

Earlier, we have defined the three alternate methods to solve this issue. Python users can use any of these methods as per their needs. But there is one thing that you have to keep in mind that is the speed and the length of the code.

Hope we have provided a valid explanation for your issue. But still, there is any confusion and anything that is not clear to you, comment it in the comment section. We will be glad to help you as my only and only aim to help you with your Python queries.  Master Python and other programming language courses from the Experts. 

Keep in touch with our Python blogs to enhance your conceptual knowledge about Python.”


Here are some interesting questions to practice your just acquired knowledge concerning why does ‘a ==x or y or z’ always evaluate to true?

1. What type of operator is “==”?

(A) Relational operator

(B) Comparison operator

(C) Assignment operator

(D) (A) & (B) Both

Correct Answer: (D) We use the “==” operator to compare the two operands. And the comparison operator is also known as a relational operator as “==” finds out the relation among both operands. This provides an answer to the most asked question- why does ‘a ==x or y or z’ always evaluate to true?

2. What is the output of the following program:

p = 20

q = 9

r = 1

if ( p == q ):

   print (“p is equal to q”)


   print (“p is not equal to q”)

(A) p is equal to q

(B) p is not equal to q

(C) Error

(D) None

Correct Answer: (B) As you can see that p is not equal to q. That is why the “==” operator compares both operands and takes them as FALSE. So, the else condition will be followed.

3. Check whether the statement is TRUE or FALSE.

The code with the “==” operator will execute the result as TRUE if and only if the expression is equal, otherwise it shows FALSE.

(A) True

(B) False

Correct Answer: (A) This is true that the “==” operator shows the output as TRUE if the expression is equal. That said, now you know why does ‘a ==x or y or z’ always evaluate to true?

4. Can a Python user use the “==” operator to check the identity of the two objects?

(A) Yes

(B) No

Correct Answer: (A) The “==” operator can compare the identities of two objects. Python users can use it as id(x) == id(y).

5. Check whether the statement is true or false.

The in operator checks if the specified values are a constituent item of the sequence such as an array, tuple, string, or list or not.

(A) False

(B) True

Correct Answer: (B) This statement is true as the “in” operator can check the sequence values.

So, we are positive that you got a solution to the question- Why Does ‘a ==x or y or z’ Always Evaluate To True? In the same vein, to master Python with the help of more detailed blogs like this, stay tuned with GUVI


A traveler, and explorer, Archana is an active writer at GUVI. You can usually find her with a book/kindle binge-reading (with an affinity to the mystery/humor).

0 0 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
personal injury lawyer colorado springs

Everything is very open with a clear clarification of the issues.
It was truly informative. Your website is useful. Thanks for sharing!

10 months ago

Hey there! I simply would like to give you a huge thumbs
up for your excellent information you have here on this
post. I am returning to your blog for more soon.

personal injury car accident lawyer

I am regular visitor, how are you everybody? This article posted at this site is genuinely

8 months ago

Great goods from you, man. I’ve understand your stuff previous to and you are just too magnificent.
I actually like what you have acquired here, really like what you’re saying and the way in which you
say it. You make it enjoyable and you still take care of to keep it sensible.
I can’t wait to read far more from you. This is actually a great website.

8 months ago

I am really happy to glance at this webpage posts which
carries lots of valuable data, thanks for providing such data.

numbers to text for fun

It’s the best time to make some plans for the future and it’s time to be happy.
I have read this post and if I could I want to suggest you some interesting things or tips.
Perhaps you could write next articles referring to this
article. I desire to read even more things about it!

Wood flooring
8 months ago

Howdy! I know this is kinda off topic however I’d figured I’d ask.
Would you be interested in exchanging links or maybe guest authoring a blog post or vice-versa?
My blog discusses a lot of the same topics as yours and I think we could greatly benefit
from each other. If you might be interested feel free to send me an email.
I look forward to hearing from you! Excellent blog
by the way!

8 months ago

Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.

You clearly know what youre talking about, why
throw away your intelligence on just posting videos to your weblog
when you could be giving us something informative to

vedligeholdelsesfrit hegn

Hello there! This article could not be written any better!
Going through this post reminds me of my previous roommate!
He continually kept talking about this. I most certainly will send this
post to him. Pretty sure he will have a great read. Thanks for sharing!


[…] When should I use the “is” and “==” operator? […]

Back to top
Would love your thoughts, please comment.x