Operators are used to perform operations on variables and values.
In the example below, we use the + operator to add together two values:
print(10 + 5)
Python divides the operators in the following groups:
Python Arithmetic Operators
Arithmetic operators are used with numeric values to perform common mathematical operations:
Python Assignment Operators
Assignment operators are used to assign values to variables:
Python Comparison Operators
Comparison operators are used to compare two values:
Python Logical Operators
Logical operators are used to combine conditional statements:
Python Identity Operators
Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location:
Python Membership Operators
Membership operators are used to test if a sequence is presented in an object:
Python Bitwise Operators
Bitwise operators are used to compare (binary) numbers:
Test Yourself With Exercises
Multiply 10 with 5, and print the result.
Start the Exercise
Python Operators in general are used to perform operations on values and variables. These are standard symbols used for the purpose of logical and arithmetic operations. In this article, we will look into different types of Python operators.
Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division.OperatorDescriptionSyntax+Addition: adds two operandsx + y–Subtraction: subtracts two operandsx – y*Multiplication: multiplies two operandsx * y/Division (float): divides the first operand by the secondx / y//Division (floor): divides the first operand by the secondx // y%Modulus: returns the remainder when first operand is divided by the secondx % y**Power : Returns first raised to power secondx ** y
# Examples of Arithmetic Operator a =9 b =4 # Addition of numbers add =a +b # Subtraction of numbers sub =a -b # Multiplication of number mul =a *b # Division(float) of number div1 =a /b # Division(floor) of number div2 =a //b # Modulo of both number mod =a %b # Power p =a **b # print results print(add) print(sub) print(mul) print(div1) print(div2) print(mod) print(p)
13 5 36 2.25 2 1 6561
For more, checkout W3Schools and Geeks For Geeks.