Operators in Python

    Kedar Kabra4 min readUpdated

    Operators are the symbols that let you do work with values — add numbers, compare them, or combine conditions. Here's a quick taste of the main groups:

    print(10 + 3)      # arithmetic: 13
    print(10 > 3)      # comparison: True
    print(True and False)  # logical: False
    

    Let's go group by group.

    Arithmetic operators

    These do basic maths:

    a = 17
    b = 5
    
    print(a + b)    # addition       -> 22
    print(a - b)    # subtraction    -> 12
    print(a * b)    # multiplication -> 85
    print(a / b)    # division       -> 3.4  (always a float)
    print(a // b)   # floor division -> 3    (drops the remainder)
    print(a % b)    # modulo         -> 2    (the remainder)
    print(a ** b)   # exponent       -> 1419857 (17 to the power 5)
    

    Two of these surprise beginners. / always gives a float, even 10 / 2 is 5.0. The % (modulo) operator gives the remainder — it's incredibly useful for checking even/odd numbers or wrapping values around.

    # Modulo is great for checking divisibility
    number = 14
    if number % 2 == 0:
        print("Even")   # 14 % 2 is 0, so this runs
    else:
        print("Odd")
    

    Comparison operators

    These compare two values and always return a boolean (True or False):

    print(5 == 5)    # equal to            -> True
    print(5 != 3)    # not equal to        -> True
    print(5 > 3)     # greater than        -> True
    print(5 < 3)     # less than           -> False
    print(5 >= 5)    # greater or equal    -> True
    print(5 <= 4)    # less or equal       -> False
    

    Remember: == compares, while a single = assigns. This is one of the most common beginner mix-ups.

    Logical operators

    These combine boolean values: and, or, not.

    age = 20
    has_id = True
    
    # 'and' is True only when BOTH sides are True
    print(age >= 18 and has_id)   # True
    
    # 'or' is True when AT LEAST ONE side is True
    print(age < 18 or has_id)     # True
    

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses

    'not' flips a boolean

    print(not has_id) # False

    
    A handy detail: Python evaluates these left to right and stops early. In `age >= 18 and has_id`, if `age >= 18` is already `False`, Python doesn't even check `has_id`. This is called *short-circuit* evaluation.
    
    ## Assignment operators
    
    The plain `=` assigns a value. The compound operators let you update a variable in place:
    
    ```python
    score = 10
    score += 5    # same as: score = score + 5  -> 15
    score -= 3    # -> 12
    score *= 2    # -> 24
    score //= 5   # -> 4
    print(score)
    

    These are shortcuts you'll use constantly, especially += inside loops to build up a total.

    A practical example

    # A simple shopping calculation with a discount
    
    price = 1200          # price of one item
    quantity = 3          # how many
    total = price * quantity   # 3600
    
    # Apply a 10% discount only if total is over 3000
    if total > 3000:
        total -= total * 0.10   # subtract 10%
    
    print(f"Amount to pay: {round(total, 2)}")
    

    Common mistakes

    • Using = instead of ==: if x = 5: is a syntax error. Comparison needs ==.
    • Expecting integer division from /: 10 / 2 gives 5.0, not 5. Use // when you want a whole-number result.
    • Writing &&, ||, !: Those are from C/Java. Python uses the words and, or, not.
    • Chaining comparisons carelessly: Python does allow 1 < x < 10, which is neat — but don't assume every language does. Inside Python it works exactly as you'd read it.
    • Forgetting operator precedence: 2 + 3 * 4 is 14, not 20, because * runs before +. Use parentheses to make intent clear: (2 + 3) * 4.

    FAQ

    What does % do with floats? It still gives a remainder: 7.5 % 2 is 1.5. It works on floats just like integers.

    Is there a ++ operator like in C? No. Python has no ++ or --. Use x += 1 to increase a value by one.

    What's the difference between is and ==? == checks if two values are equal; is checks if they are the same object in memory. Beginners should almost always use ==.


    Operators really shine inside decisions and loops. Continue with If-Else Statements in Python and Loops in Python, or browse the full Python learning hub.

    Want to learn this properly? Join the waitlist for our Python course — taught in Jalgaon, beginner-friendly.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses
    Kedar Kabra

    Instructor, Infoplanet

    Kedar Kabra teaches Python at Infoplanet, helping beginners become confident programmers through hands-on, project-first practice.

    Related guides