My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

PYTHON OPERATORS : Comparison and Arithmetic Operators.

Modupe Falodun's photo
Modupe Falodun
·Jun 13, 2020

PYTHON OPERATORS

Operators in python is a core fundamental concept in python. Operators are symbols in python which are used to carry out computations on values or variables. Simply put they are used to manipulate values/ variables to produce results. These values that are operated on are called operands. For example if we have 2 + 4, 2 and 4 are our operands while "+" is our operator. There are several operator types in python namely:

• Comparison operators • Arithmetic operators • Logical operators • Assignment operators • Identity operators • Membership operators • Bitwise operators.

However, for this tutorial, we will be focusing on the Comparison operators and the Arithmetic operators. Let’s jump right in.

What are Comparison Operators? As the name implies, comparison operators are used to compare two values. They tell us how one value relates to the other. They return either “True” or “False” depending on the condition. Examples of comparison operators include (==, != , >,<, >=,<=,). They are also called relational operators. Now what do these symbols mean and when can we use them.

Comparison Operator Symbols.JPG

So now that we know what comparison operators are, let’s try a simple example.

Comparison Operator.JPG

Here in example, our value of x = 2 is smaller than y = 7, so when we print the value as x>y, it actually compares the value of x to y and since x is actually not greater than y, it returns "False". That was quite easy right. Now try it on your own and let me know how that goes. You can also try with other operators to get yourself familiar with how each of them works.

What are Arithmetic Operators? Arithmetic operators are used to perform various mathematical calculations like addition, subtraction, division, etc. For this operator type, our output would be a numerical value. Below are the arithmetic operators with names and their symbols.

Arithmetic Operator Symbols.JPG Easy enough right. Now let’s try a simple example.

Arithmetic Operators.JPG

I do hope this was easy enough. Please try out the other arithmetic operators and let me know how it goes in the comment section.

Thanks for reading!