Next

Operators in Python

  • Operators in Python are special symbols used to perform operations on values and variables. They allow programmers to carry out calculations, compare values, make decisions, and control program logic. Python provides several types of operators such as arithmetic operators for calculations, comparison operators for checking conditions, logical operators for combining conditions, and assignment operators for storing values.

  • What is an Operator in Python?

    An operator is a symbol that tells Python to perform a specific operation on one or more values.
    Operators are used for calculations, comparisons, and decision-making in programs.

Adding Two Numbers Using Arithmetic Operator

This code adds two numbers using the + operator. The result of a + b is displayed using the print() function.

a = 10
b = 5
print(a + b)
  • + is the operator.

    What is an Operand in Python?

    An operand is the value or variable on which an operator works.
    Operands can be numbers, strings, variables, or expressions.

    Example:

    a + b

    Here:

    • a and b are operands

    • + is the operator

    Operator vs Operand 

    Operator

    Operand

    Performs an action

    Value on which action is performed

    Example: + , - , *

    Example: 10 , x , "Python"

    Types of Operators in Python


    1. Arithmetic Operators – Used for mathematical operations
    + , - , * , / , % , ** , //

    2. Comparison Operators – Used to compare values
    == , != , > , < , >= , <=

    3. Logical Operators – Used to combine conditions
    and , or , not

    4. Assignment Operators – Used to assign values
    = , += , -= , *= , /=

    5. Membership Operators – Check whether a value exists in a sequence
    in , not in

    6. Identity Operators – Compare memory location of objects
    is , is not

    7. Bitwise Operators – Work on binary values
    & , | , ^ , ~ , << , >>
Next