Sunday, 21 May 2017

Beginner Python Programming Tutorial - How to become a Python Jedi - Part 4 - Comparison Operators

Welcome back friends to another post on TheCodingProject and we are back with the fourth chapter of the Python programming tutorial - How to become a python Jedi. This time we are going to learn about comparison operators.

What are Comparison Operators ?
Comparison operators are used to compare any two values, be it two numbers , two strings or any other objects. In short these operators help us to make a decision by giving back the results of a comparison. Comparison operators always return either a True or a False.

Different Comparison opearators →
== Equal to
!=  Not equal to
<   Less than
>   greater than
<= Less than or equal to
>= Greater than or equal to

Examples of Comparison operators →
Let’s get into some examples to better understand the usage of comparison operators. Copy the below code and paste it in pycharm or any other editor that you have. Additionally you can also download the comparison code file of this tutorial from github. →

For the first print statement the Equals to operator denotes that we want to compare that whether the integers 1 & 2 are equal to each other or not. When the control finds that both the integer values are not equal then it returns a False. Similarly for the second print statement when control finds that the two strings are not equal to each other so it returns a False once again. But in the third print statement we are comparing to see if 45 is greater than 34 and since it’s true, so a value True is returned. Similarly in the last print statement since 56 is equal to 56, so the condition less than or equal to evaluates to True.  
So, folks this was all for this week but we shall return with another chapter of this tutorial with some new concepts to learn.

Subscribe to my youtube channel to watch the coding in this tutorial in action.

If you have any questions, suggestions or comments you can post your comment here or you can also bug me on Quora, Twitter or on Facebook.

No comments:

Post a Comment