Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . Python Operators - Complete Guide

Python Operators - Complete Guide

Become More Then A coder | Learn & Start Coding Now.

✅ Python Operators – Complete Guide with Examples


🔹 What are Operators in Python?

Operators are symbols used to perform operations on variables and values.
Python has several categories of operators.

a = 10
b = 5
print(a + b)  # Output: 15

🔸 1. Arithmetic Operators

Used to perform mathematical operations.

Operator Description Example
+ Addition a + b
- Subtraction a - b
* Multiplication a * b
/ Division a / b
% Modulus (remainder) a % b
** Exponentiation a ** b
// Floor Division a // b

✅ Example:

a = 10
b = 3

print(a + b)  # 13
print(a - b)  # 7
print(a * b)  # 30
print(a / b)  # 3.33
print(a % b)  # 1

🔸 2. Assignment Operators

Used to assign values to variables.

Operator Description Example
= Assign a = 5
+= Add and assign a += 2
-= Subtract and assign a -= 3
*= Multiply and assign a *= 4
/= Divide and assign a /= 2
%= Modulus and assign a %= 3

✅ Example:

a = 5
a += 2      # a = a + 2 → 7
print(a)    # 7

🔸 3. Comparison Operators

Used to compare two values and return True or False.

Operator Description Example
== Equal to a == b
!= Not equal to a != b
> Greater than a > b
< Less than a < b
>= Greater or equal a >= b
<= Less or equal a <= b

✅ Example:

a = 10
b = 5
print(a > b)   # True
print(a == b)  # False

🔸 4. Logical Operators

Used to combine conditional statements.

Operator Description Example
and True if both a > 5 and b < 5
or True if any one a > 5 or b < 2
not Reverse the result not(a > b)

✅ Example:

a = 10
b = 5

print(a > 5 and b < 10)  # True
print(a < 5 or b == 5)   # True
print(not a == b)        # True

🔸 5. Identity Operators

Check if two variables point to the same object.

Operator Description Example
is Same identity a is b
is not Different identity a is not b

✅ Example:

x = [1, 2]
y = [1, 2]
z = x

print(x is z)       # True
print(x is y)       # False
print(x is not y)   # True

🔸 6. Membership Operators

Check if a value exists in a sequence (list, string, tuple).

Operator Description Example
in Present in sequence "a" in "Arvind"
not in Not present "z" not in "AI"

✅ Example:

skills = ["Python", "AI", "ML"]
print("Python" in skills)    # True
print("Java" not in skills)  # True

🔸 7. Bitwise Operators

Operate on binary numbers (bit-level).

Operator Description Example
& AND a & b
` ` OR
^ XOR a ^ b
~ NOT ~a
<< Left Shift a << 1
>> Right Shift a >> 1

✅ Example:

a = 5    # 0101
b = 3    # 0011

print(a & b)  # 1
print(a | b)  # 7
print(~a)     # -6

✅ Summary Table

Category Operators
Arithmetic + - * / % // **
Assignment = += -= *= /=
Comparison == != > < >= <=
Logical and or not
Identity is, is not
Membership in, not in
Bitwise `&

✅ Real-World Use Example:

username = "arvind"
password = "1234"

if username == "arvind" and password == "1234":
    print("Login successful")
else:
    print("Access denied")

✅ Best Practices

  • Use parentheses for clarity: (a > 5 and b < 10)
  • Don't confuse = (assign) with == (compare)
  • Use is for identity (not equality)
  • Always write readable conditions



Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.