Types of Operators in Python Programming - Complete Guide

Types of Operators in Python Programming

In Python programming, operators are symbols or characters that perform various operations on operands (variables or values). Here is a complete guide to the types of operators in Python:

Types of Operators in Python

1. Arithmetic Operators:

Addition (+): Adds two operands.

Subtraction (-): Subtracts the second operand from the first.

Multiplication (*): Multiplies two operands.

Division (/): Divides the first operand by the second (returns a float).

Floor Division (//): Divides the first operand by the second and rounds down to the nearest integer.

Modulo (%): Returns the remainder of the division between two operands.

Exponentiation (**): Raises the first operand to the power of the second.

2. Assignment Operators:

Assignment (=): Assigns a value to a variable.

Addition Assignment (+=): Adds the right operand to the left operand and assigns the result to the left operand.

Subtraction Assignment (-=): Subtracts the right operand from the left operand and assigns the result to the left operand.

Multiplication Assignment (*=): Multiplies the right operand with the left operand and assigns the result to the left operand.

Division Assignment (/=): Divides the left operand by the right operand and assigns the result to the left operand.

Modulo Assignment (%=): Calculates the remainder of dividing the left operand by the right operand and assigns the result to the left operand.

Exponentiation Assignment (**=): Raises the left operand to the power of the right operand and assigns the result to the left operand.

Floor Division Assignment (//=): Divides the left operand by the right operand and assigns the floor division result to the left operand.

Also read: When Python is Invented? Complete Guide

3. Comparison Operators:

Equal to (==): Returns True if the operands are equal, False otherwise.

Not equal to (!=): Returns True if the operands are not equal, False otherwise.

Greater than (>): Returns True if the left operand is greater than the right operand, False otherwise.

Less than (<): Returns True if the left operand is less than the right operand, False otherwise.

Greater than or equal to (>=): Returns True if the left operand is greater than or equal to the right operand, False otherwise.

Less than or equal to (<=): Returns True if the left operand is less than or equal to the right operand, False otherwise.

4. Logical Operators:

Logical AND (and): Returns True if both operands are True, False otherwise.

Logical OR (or): Returns True if either of the operands is True, False otherwise.

Logical NOT (not): Returns the opposite Boolean value of the operand.

Also read: Top 10 Websites for Python Quizzes

5. Bitwise Operators:

Bitwise AND (&): Performs bitwise AND operation between the binary representations of two operands.

Bitwise OR (|): Performs bitwise OR operation between the binary representations of two operands.

Bitwise XOR (^): Performs bitwise XOR (exclusive OR) operation between the binary representations of two operands.

Bitwise NOT (~): Performs bitwise NOT (one's complement) operation on a single operand.

Left Shift (<<): Shifts the bits of the left operand to the left by the number of positions specified by the right operand.

Right Shift (>>): Shifts the bits of the left operand to the right by the number of positions specified by the right operand.

Also read: How to install Python on Windows and set a path variable?

6. Membership Operators:

in: Returns True if a value is found in the specified sequence, False otherwise.

not in: Returns True if a value is not found in the specified sequence, False otherwise.

7. Identity Operators:

is: Returns True if both operands refer to the same object, False otherwise.

is not: Returns True if both operands do not refer to the same object, False otherwise.

These are the different types of operators available in Python programming. Understanding and utilizing these operators will allow you to perform a wide range of operations in your Python code. If you are learning Python programming then visit the Tutorials Freak website for the Python tutorial

Post a Comment

Previous Post Next Post