# Python Operators

In this tutorial you will learn:

• Python Operators
• Assignment Operators
• Arithmetic Operators
• Comparison Operators
• Logical Operators

Python Operators

Operators are considered as the foundation of any programming language. Operators are symbols which can control the value of operands by performing different tasks based on the type of symbol.

Assignment Operators

These operators as the name suggests are used to set values to the operands, they set the values on the right side of the operator to the left side of the operator. Following are some commonly used Python operators and their meaning:

Operator Description
= Assign value from right side to left side.
+= Sum values to an operand. It’s equivalent to `myVar = myVar + 1`.
-= Subtracts values from a operand equivalent to `myVar = myVar - 1`.
/= Divides values from left hand side by right hand side and assign it to left hand side. It’s equivalent to to `myVar = myVar / 1`.

Arithmetic Operators

These are the most important Operators in any programming language. The common ones are +, -, *, / and %.

Operator Description
+ Sums the values on left and right side of the operator.
- Subtracts the values on left and right side of the operator.
* Multiplies the values on left and right side of the operator.
/ Divides the values on left by right side value of the operator.
% Divides the values on left by right side value of the operator and returns the remainder.
** This operator is used to do exponential calculations. It’s a unique operator in Python.

Comparison Operators

These operators are used to compare values.

Operator Description
> Checks if value on the left side of the operator is greater than the right side value.
>= Checks if value on the left side of the operator is greater than or equal to the right side value.
< Checks if value on the left side of the operator is less than to the right side value.
<= Checks if value on the left side of the operator is less than or equal to the right side value.
== Checks if value on the left side of the operator is exactly equal to the right side value.
!= Checks if value on the left side of the operator is not equal to the right side value.

Logical Operators

These operators used to join conditional statements.

Operator Description
not This operator reverses the result if it’s true then it will be changed to false and vice versa.
and This operator will return true if both conditions are true.
or This operator will return true if either one condition is true.