Python Operators
Python operators are symbols or keywords used to perform operations on variables and values. They help in performing arithmetic, logical, comparison, and other operations in programs
OPERATORS
What is Operator?
Python Operators are generally used to perform operations on values and variables
Operators: These are the special symbols
Ex: +, *, /, - etc.
Operands: 1. In python, operators are special that perform some sort of operation on values
2. The values that an operator acts on are called operands
3.Here operands are nothing but variables
Types of Operators:
1.Airthematic Operators
2.Relational Operators or Comparison Operators
3.Assignment Operators
4.Logical Operators
1.Airthematic Operators:
Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc
|
Operator |
Name |
Example |
Result |
|
+ |
Addition |
5 + 3 |
8 |
|
- |
Subtraction |
5 - 3 |
2 |
|
* |
Multiplication |
5 * 3 |
15 |
|
/ |
Division |
5 / 2 |
2.5 |
|
// |
Floor Division |
5 // 2 |
2 |
|
% |
Modulus (Remainder) |
5 % 2 |
1 |
|
** |
Exponential |
2 ** 3 |
8 |
Arithmetic operators with input:
2.Relational Operators or Comparison Operators:
Comparison operators are used to compare two values. They return Boolean values: either TRUE or FALSE
|
Operator |
Name |
Example |
Result |
|
== |
Equal to |
5 == 5 |
True |
|
!= |
Not equal to |
5!= 3 |
True |
|
> |
Greater than |
5 > 3 |
True |
|
< |
Less than |
5 < 3 |
False |
|
>= |
Greater than or equal |
5 >= 5 |
True |
|
<= |
Less than or equal |
3 <= 5 |
True |
Conditional Operators with input:
3.Python Assignment Operators:
Assignment operators are used to assign values to variables. They can also perform operations and assign the result back to the variable.
|
Operator |
Description |
Example |
Same As |
|
= |
Assign |
a = 5 |
Assign 5 to a |
|
+= |
Add and assign |
a += 3 |
a = a + 3 |
|
-= |
Subtract and assign |
a -= 2 |
a = a - 2 |
|
*= |
Multiply and assign |
a *= 4 |
a = a * 4 |
|
/= |
Divide and assign |
a /= 2 |
a = a / 2 |
|
%= |
Modulus and assign |
a %= 3 |
a = a % 3 |
|
//= |
Floor divide and assign |
a //= 2 |
a = a // 2 |
|
**= |
Exponent and assign |
a **= 3 |
a = a ** 3 |
Assignment operators with input:
4.Logical Operators:
Logical operators are used to combine conditional (Boolean) statements.
|
Operator |
Description |
Example (a = True, b =False) |
Result |
|
and |
Returns True if both statements are true |
a and b |
False |
|
or |
Returns True if at least one is true |
a or b |
True |
|
not |
Reverses the result (True → False, etc.) |
not a |
False |

