Artcafe Easy Programming Learning - Python programming part 3

ArtCafe
1

Operators in Python Programming


We studies what are the variables that used in the Python Programming in last blog session Artcafe. If someone missed that post please visit here and continue with this lesson.

What is the operators in the python programming, let’s consider this mathematical expression.

5+3 =8

In this expression, we all know, it is the way to get the sum of 5 and 3. So this Addition is a one of a Operator in the Python Programing. There are more Operators. Because when solving a problem, we have to use that Operators regularly. There are 4 main types of Operators in Python programming.
  1. Arithmetic Operators
  2. Comparison Operators
  3. Logical Operators
  4. Assignment Operators

Arithmetic Operators

This Arithmetic Operators are used for mathematical uses. Example addition, subtractions.  I will explain what that operators and examples are using below table.

Operator
Usage
Example Expression
+
Addition
5+3 = 8
-
Subtraction
5-3 = 2
*
Multiplication
5*3 = 15
/
Division
15/5 =3
%
Modulus
3%2 =1
**
Exponent
3**2 = 9
//
Floor Division
3//2 = 1

Let’s create a simple python program to test this Arithmetic Operators. Open the Python shell and Code the following codes using Script mode. Then run the script.  If you don’t know how to run a python script using Script mode, please visit here.


artcafe blog python programming arithmatic operators

When you run that program it will give outputs like below. So I hope you got a basic idea about Arithmetic Operators in Python.
artcafe blog python programming arithmatic operators result

Comparison Operators

Comparison Operators are compare the left and right side of an expression and give a idea of the connection between them. For example, Lets take 5<8 (five less than eight). This expression is true, because we know 5 is less than eight.  If there is another expression like 4<2 (Four less than two). What do you think about the result? Yes, the result should be false. Because 4 is not less than 2. Like that we use this Comparison Operators. You can take good idea about Python Comparison Operators by studying below table. 

Operator
Usage
Example Expression
Result
< 
less
4 < 5
true

5 < 4
false
> 
greater
7 > 5
true

5 > 7
false
==
equal
5 == 5
true

5 == 2
false
!=
Not equal
4 != 5
true

4 != 4
false
>=
Greater than or equal
3 >= 2
true

2 >=2
false
<=
Less than or equal
3 <= 2
false

2 <= 2
true
I will explain more about this comparison Operators by using another example. If we consider the 3>=2 expression, There are two conditions in the Operator.1st one is 3>2 and second one is 3==2. If one of these two condition give result “true”, this 3>=2 expression output the result “true”. Else it output the “false”.  I will create a small program to use this Comparison Operators in Python Program.

Like before Open the Python shell and Code the following codes using Script mode. Then run the script.
artcafe blog python programming comparison operators

When you run that program it will give outputs like below. So I hope you got a basic idea about Arithmetic Operators in Python.
artcafe blog python programming comparison operators result

In this lesson, we learned the Python Arithmetic Operators and Comparison Operators. If you have any subject matter or anything, please use the comment box. I will happy to help you. To be continued. Please wait for more Operators in next lesson. Thank you

Post a Comment

1Comments
  1. Excellent post. You have shared some wonderful tips. I completely agree with you that it is important for any blogger to help their visitors. Once your visitors find value in your content, they will come back for more How to Run Python Program In Script Mode



    ReplyDelete
Post a Comment