Skip to main content

Logical operators in python : Beginner Python Programming Tutorial - How to become a Python Jedi - Part 3-4



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 logical operators.

What are Logical Operators ?
Logical 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. logical operators always return either a True or a False.

Different Logical operators →
== Equal to
!=  Not equal to
<   Less than
>   greater than
<= Less than or equal to
>= Greater than or equal to

Examples of Logical 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 operators.py 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.


Comments

Popular posts from this blog

What I learned from writing a guest post

                                                     Recently I wrote a python tutorial for Datacamp , while writing this tutorial I learned a couple of things which I am going to share with you right here in my blog post. May be you can use my experiences in your own endeavours as a writer. Idea The first step is idea generation. You can either search through any previous topics in your blog post if you have one or you can go through your past learning, experiences or any problem statement that you might have gone through and you will find that while doing that you can get tons of ideas to start your article. If you fall short of ideas then you can ask for help from may be your social media followings your friends or your family, for example I asked the people at Datacamp  themselves and they suggested me a couple of topics which got me started on the right note. So, be prompt to ask for help and you will be surprised how easily you can crowd-source ideas and there's noth

How To Install Tensorflow On Windows

Why I am writing this tutorial ? Recently I have started learning machine learning specifically DeepLearning for one of my pet projects, and during this quest of mine I wanted to learn TensorFlow library which is developed by Google. Learning is one thing but first I needed to install the library, but there was this problem which I faced during the installation. I am using Anaconda as my package manager and trying to install the Tensorflow library on my work computer which is behind a proxy, installing directly from the anaconda cloud while behind a proxy always displayed a proxy error. How did I resolve the issue? Well this is exactly what I am going to write down in the below tutorial. The Steps To Follow Before we get all cosy with this short tutorial on Tensorflow installation, let me tell you that this tutorial is on the assumption that you have already installed Anaconda on your machine and you know at least a few basic things or two about python. If y

Collatz sequence python : Monday fun with Python

Hello everyone. Today is Monday..well not a big deal and I know everyone knows today is a Monday. Like you I'm not a big fan of Monday, although nowadays I'm waiting eagerly for this day of the week as I get to watch a Game of Thrones episode on this day and I'm sure most of you can reciprocate the same feeling. The only thing I hate the most is the long wait till Monday night till I return to home from office and get to watch that episode for which I wait for one whole week and here I am in office waiting for the day to get over soon. The plan To kill the time I do one of the thing that I love the most. Yes, you guessed right? I code. So, I decided to fool around some python programming code to kill the boredom. Without much ado let's code :) I decided to device a python program that would help me to devise a "collatz sequence" In case you are thinking what a "collatz sequence" is then dive into this link here . For more understanding on pyt