For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.
It makes sense to start learning by reading and watching videos about fundamentals and how things work.
Data Science and Machine Learning - 16 wks
Full-Stack Software Developer - 16w
Search from all Lessons
Curated list of small interactive and incremental exercises you can take to get better at any coding skill.
Curated section of projects to build while learning with simple instructions, videos, solutions, and more.
Guides on different topics related to the technologies that we teach in our courses
Social & live learning
The most efficient way to learn: Join a cohort with classmates just like you, live streams, impromptu coding sessions, live tutorials with real experts, and stay motivated.
Javier Leyva Seiglie
In Python, the double equal sign
== is a relevant operator that is used to compare two variables or values and determine whether they are equal or not. We will explore the utility of this operator in Python and how can be used in different situations. We prepared an article as an Intro to Python that we recommend to check before reading the following piece of content. Let’s start with a quick example so we can understand its functionality.
Let’s suppose that we have 2 variables called
b with the following values assigned to:
Now, we want to verify if
a is equal to
b by using the double equal sign operator:
On the previous example, we declared 2 variables
b with values 5 and 10 respectively. Then, we used the double equal sign operator in an if-else block to compare
b values. Finally, if
a is equal to
b, our code will print
"a is equal to b", otherwise it will print
"a is not equal to b".
This operator in Python shows a comparison used to verify if a value is equal to another one. In this way, Python compares values on both sides of the operator and returns
True if they are equal and
False if they are not. Now, let's see different conditions' use cases.
In the previous example, we have two variables with the same numbers as values. When using the double equal sign
==, the program will print
"Both numbers are the same" since both variables have the same number.
In this case, we have two variables that contain strings as values. Due to both strings being different, our code will print
"Names are different".
Let's see our final example:
Finally, in this last example, we are comparing two boolean variables and because they are different, our code will print
"Both values are different" as expected.
The double equal sign operator in Python is completely essential when we want to compare values and evaluate conditions with if statements. This allows us to check if values are the same or not, which leads to different outputs depending on the values we have on variables.
We hope you can understand the use and importance of the double equal sign operator in Python. Now, you can enhance your programming skills with this knowledge and take better decisions in your apps. You can check the 4Geeks Blog for more amazing content.