Python Operators and Their Uses
🔢 1. Arithmetic Operators
Used for basic mathematical operations.
Operator Description Example Result
+ Addition 3 + 2 5
- Subtraction 3 - 2 1
* Multiplication 3 * 2 6
/ Division 3 / 2 1.5
// Floor Division 3 // 2 1
% Modulus (remainder) 3 % 2 1
** Exponentiation 3 ** 2 9
🔁 2. Assignment Operators
Used to assign values to variables.
Operator Example Same As
= x = 5 assign 5 to x
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
**= x **= 2 x = x ** 2
//= x //= 2 x = x // 2
❓ 3. Comparison Operators
Used to compare values (returns True or False).
Operator Description Example
== Equal to 3 == 3
!= Not equal to 3 != 2
> Greater than 3 > 2
< Less than 2 < 3
>= Greater than or equal 3 >= 3
<= Less than or equal 2 <= 3
🔘 4. Logical Operators
Used to combine conditional statements.
Operator Description Example
and True if both are true True and False → False
or True if at least one is true True or False → True
not Inverts the result not True → False
📦 5. Bitwise Operators
Used to perform bit-level operations.
Operator Description Example
& AND 5 & 3 → 1
` ` OR
^ XOR 5 ^ 3 → 6
~ NOT ~5 → -6
<< Left Shift 5 << 1 → 10
>> Right Shift 5 >> 1 → 2
📋 6. Membership Operators
Used to test for membership in a sequence (like lists, strings, etc.).
Operator Description Example
in True if value is present 'a' in 'apple' → True
not in True if value is not present 'x' not in 'apple' → True
🧱 7. Identity Operators
Used to compare memory locations.
Operator Description Example
is True if same object x is y
is not True if not same object x is not y
Learn Python Course in Hyderabad
Read More
Python Input and Output Functions
Introduction to Python: Why Learn It?
Visit Our Quality Thought Training in Hyderabad
Comments
Post a Comment