What Are Operators in Python and There Different Types - Complete Guide

 

Different Types of Python

In Python, operators are symbols or keywords used to perform various operations on values or variables. 

Different Types of Python

Python provides several types of operators, which can be categorized as follows:

Arithmetic Operators:

Arithmetic operators are used to perform basic mathematical operations. The following are the arithmetic operators in Python:

Addition (+): adds two operands.

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

Multiplication (*): multiplies two operands.

Division (/): divides the first operand by the second operand.

Modulus (%): returns the remainder when the first operand is divided by the second operand.

Floor Division (//): returns the integer quotient when the first operand is divided by the second operand.

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

Also read: What are the Advantages of Python Programming?

Comparison Operators:

Comparison operators are used to compare two values or variables. The following are the comparison operators in Python:

Equal to (==): returns True if the two operands are equal.

Not equal to (!=): returns True if the two operands are not equal.

Greater than (>): returns True if the first operand is greater than the second operand.

Less than (<): returns True if the first operand is less than the second operand.

Greater than or equal to (>=): returns True if the first operand is greater than or equal to the second operand.

Less than or equal to (<=): returns True if the first operand is less than or equal to the second operand.

Logical Operators:

Logical operators are used to combine two or more conditional statements. The following are the logical operators in Python:

And: returns True if both the operands are True.

Or: returns True if at least one of the operands is True.

Not: returns the opposite of the operand's Boolean value.

Assignment Operators:

Assignment operators are used to assign values to variables. The following are the assignment operators in Python:

Equals (=): assigns the value on the right to the variable on the left.

Plus Equals (+=): adds the value on the right to the variable on the left and assigns the result to the variable on the left.

Minus Equals (-=): subtracts the value on the right from the variable on the left and assigns the result to the variable on the left.

Times Equals (*=): multiplies the variable on the left by the value on the right and assigns the result to the variable on the left.

Divide Equals (/=): divides the variable on the left by the value on the right and assigns the result to the variable on the left.

Modulus Equals (%=): returns the remainder when the variable on the left is divided by the value on the right and assigns the result to the variable on the left.

Floor Divide Equals (//=): returns the integer quotient when the variable on the left is divided by the value on the right and assigns the result to the variable on the left.

Exponentiation Equals (**=): raises the variable on the left to the power of the value on the right and assigns the result to the variable on the left.

Also read: What is Python Programming Language? Definition and Introduction

Membership Operators:

Membership operators are used to test if a value or variable is a member of a sequence or collection. The following are the membership operators in Python:

In: returns True if the value on the left is a member of the sequence or collection on the right.

Not In: returns True if the value on the left is not a member of the sequence or collection on the right.

Identity Operators:

Identity operators are used to test if two values or variables refer to the same object in memory. The following are the identity operators in Python:

Is: returns True if the two operands refer to the same object in memory.

If you are want to learn Python then visit the visit the given link which is completely free Python Tutorial for beginner.

Post a Comment

Previous Post Next Post