Python

Python Operators

Python Operators are the special characters that carry out a certain actions in programming this may be of type arithmetic or logical computations.

They play a key role in programming by solving various problems we face in almost all the programming languages and day to day tasks as well.

Let’s deal with these operators in this blog.

Python operators are symbols that represent operations to be performed on one or more operands. Here are some of the most commonly used operators in Python:

Arithmetic operators :

These operators are used to perform basic arithmetic operations. Examples include + (addition), – (subtraction), * (multiplication), / (division), % (modulus), and ** (exponentiation).

Comparison operators :

These operators are used to compare two values and return a Boolean value (True or False) depending on whether the comparison is true or false. Examples include == (equality), != (inequality), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to).

Logical operators :

These operators are used to combine Boolean expressions and return a Boolean value. Examples include and (logical AND), or (logical OR), and not (logical NOT).

Assignment operators :

These operators are used to assign a value to a variable. Examples include = (assignment), += (addition assignment), -= (subtraction assignment), *= (multiplication assignment), /= (division assignment), and %= (modulus assignment).

Bitwise operators :

These operators are used to perform bitwise operations on binary numbers. Examples include & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NOT), << (left shift), and >> (right shift).

Membership operators :

These operators are used to test whether a value is a member of a sequence (such as a string, list, or tuple). Examples include in (membership test) and not in (negated membership test).

Identity operators :

These operators are used to test whether two objects are the same object in memory. Examples include is (identity test) and is not (negated identity test).

These are just some of the operators available in Python. Understanding how to use them is an important part of programming in Python.

Python operators video tutorial :

Arithmetic Operators :

The basic arithmetic operators are addition, subtraction, multiplication, division and modulus. Let’s try to see few arithmetic operators.

Addition :

x = 1
y = 2

x + y = 3

Subtraction :

x - y = -1

Multiplication :

x * y = 2

Division :

x / y = 0.5

Assignment Operators :

These operators are used to handle assignments now let us try to assign values to variables like

x = 5 
y = 10

Here we have assigned values to values to x and y now try to print x and y

x

5
y

10

Now try to assign the values of y to x

x = y
x 

10

Now try to add x and y because we have assigned y value to x

x + y

20

Now try to add +2 to x

x = x + 2

22

Now try to do the above step in another way i.e., adding

x += 2

24

Now try to subtract in the same way

x -= 10

14

Now try to multiply

x *= 2

28

Relational Operators :

These type of operators are helpful in relating the variables and returning output.We will be seeing 6 types of relational operators with examples.

For example compare x greater than y

x = 1
y = 2
x > y

False

x less than y

x < y

True

x greater than or equal to y

x >= y

False

Now re-assign x value to 2 and compare various scenarios

x = 2
x >= y

True

x <= y

True

x == y

True

Now see x not equal to y

x != y

False

Logical Operators :

Let’s consider a scenarios where you need to pass a exam in subjective (y) and objective (x) tests, so both the conditions to be passed to be TRUE

AND

Both the conditions need to be true to make final result to be true.

x = 10 
y = 20

x > 5 and y > 15

True

Even if one condition fails the final result is FALSE.

x > 10 and y > 15 

now x condition fails

False

OR

Any one of the both conditions needs to be true to make final result to be true.

x > 10 or y > 15

True

When both the conditions fail final result will also be false even in case of or condition.

x > 10 or y > 20

False

NOT :

This will reverse the above scenarios let see example to understand.

not x > 2

False

If you have any query’s in this tutorial on Python Operators do let us know in the comment section below.If you like this tutorial do like and share us for more interesting updates.

Refer the above video tutorial to get clear understanding with examples.

Python Operators

Abhishek

Share
Published by
Abhishek

Recent Posts

5G and 6G Technology Advancements: The Future of Connectivity

5G and 6G Technology AdvancementsWhat is 5G, and How Has It Transformed Connectivity?1. Understanding 5G…

3 days ago

HTML: The Evolution and Power of Unleashed Web Language and Modern too

IntroductionInitial StagesEvolutionChallenging Other LanguagesCurrent TrendsAI and HTMLConclusion Introduction HTML, or HyperText Markup Language, is the…

3 months ago

Increase in 80C in Budget 2024 ?

Increase in 80CDemands and Discussions: Increase in 80C Section 80C of the Income Tax Act…

4 months ago

ChatGPT 4o Unleashing the Power of GPT A Comprehensive Guide

IntroductionWhat is ChatGPT-4?Key Features of ChatGPT-4Enhanced Natural Language UnderstandingImproved Response GenerationVersatilityApplications of ChatGPT-4Customer SupportContent CreationEducational…

6 months ago

APJ Abdul Kalam Biography: A Tribute to India’s Powerful Missile Man

APJ Abdul Kalam Biography :Childhood :Academics :Professional Career :Achievements : APJ Abdul Kalam Biography :…

9 months ago

Srinivasa Ramanujan Biography: Exploring the Genius

We value your feedback! Please share your thoughts on this blog on Srinivasa Ramanujan Biography…

9 months ago

This website uses cookies.