Python Operators

Python Operators

In Python Programming, operators in general functions will perform operations on values and variables. These operators are considered as the standard symbol which functions for logical and arithmetic operations.

Let us check out this article to learn more about the different types of Python Operators.

What are Operators in Python?

Python and several programming languages have different types of operators which are the symbol and even referred to as keywords. They will do operations on one or more operands.

These operators will offer different operations such as addition, subtraction, multiplication, and division.

Types Of Operators in Python

a. Arithmetic Operator

b. Comparison Operator

c. Assignment Operator

d. Logical Operator

e. Bitwise Operators

f. Membership Operators

g. Identity Operators

Python Arithmetic Operators

Arithmetic Operators mainly function to do basic mathematical operations. Hence, the variable will have 10 and the variable b has 20.

OperatorNameExample
+Additiona + b = 30
Subtractiona – b = -10
*Multiplicationa * b = 200
/Divisionb / a = 2
%Modulusb % a = 0
**Exponenta**b =10**20
//Floor Division9//2 = 4

Python Comparison Operators

These operators have values on either side of them and can analyze the relation between them. These are also known as Relational Operators.

Suppose variable a has 10 and variable b has 20

OperatorNameExample
==Equal(a == b) is not true.
!=Not equal(a != b) is true.
>Greater than(a > b) is not true.
<Less than(a < b) is true.
>=Greater than or equal to(a >= b) is not true.
<=Less than or equal to(a <= b) is true.

Python Assignment Operators

Assignment operators will provide values to several variables. Python assignment operators table is provided below

OperatorExampleSame As
=a = 10a = 10
+=a += 30a = a + 30
-=a -= 15a = a – 15
*=a *= 10a = a * 10
/=a /= 5a = a / 5
%=a %= 5a = a % 5
**=a **= 4a = a ** 4
//=a //= 5a = a // 5
&=a &= 5a = a & 5
|=a |= 5a = a | 5
^=a ^= 5a = a ^ 5
>>=a >>= 5a = a >> 5
<<=a <<= 5a = a << 5

Python Bitwise Operators

Bitwise Operator will perform on bits and functions bit by bit operations. Moreover, these operations will compare binary numbers.

OperatorNameExample
&ANDa & b
|ORa | b
^XORa ^ b
~NOT~a
<<Zero fill left shifta << 3
>>Signed right shifta >> 3

Python Logical Operators

These operators will further compile more than 2 conditions and monitor the final result. The logical operators which are provided here will support the Python language.

OperatorNameExample
andANDa and b
orORa or b
notNOTnot(a)

Python Membership Operators

These operators will test for membership in a sequence like the strings, lists, or tuples.

OperatorDescriptionExample
inReturns True if it finds a variable in the specified sequence, false otherwise.a in b
not inan in ba not in b

Python Identity Operators

Identity operators will compare the memory locations of two objects. Those identity operators are given below

OperatorDescriptionExample
isReturns True if both variables are the same object and false otherwise.a is b
is notReturns True if both variables are not the same object and false otherwise.a is not b

Python Operators Precedence

The table below has operators from the highest precedence to the lowest.

Sr.No.Operator & Description
1**Exponentiation (raise to the power)
2~ + –Complement, unary plus and minus (method names for the last two are +@ and -@)
3* / % //Multiply, divide, modulo and floor division
4+ –Addition and subtraction
5>> <<Right and left bitwise shift
6&Bitwise ‘AND’
7^ |Bitwise exclusive `OR’ and regular `OR’
8<= < > >=Comparison operators
9<> == !=Equality operators
10= %= /= //= -= += *= **=Assignment operators
11is is notIdentity operators
12in not inMembership operators
13not or andLogical operators

Conclusion

To conclude, this article will educate us on the different types of Python operators. Python Arithmetic Operators, Python Bitwise operators, Python Logical operators, and several other operators are included in this.

Python Operators- FAQs

Q1. What is the in operator in Python?

Ans. The in-operator will monitor if a value is in a collection of values

Q2. What is init in Python?

Ans. It is considered a special method for the initialization of the object.

Q3. What is str in Python?

Ans. Python consists of a built-in string class referred to as “str” with many handy features . String literals will be enclosed by either double or single quotes.

Hridhya Manoj

Hello, I’m Hridhya Manoj. I’m passionate about technology and its ever-evolving landscape. With a deep love for writing and a curious mind, I enjoy translating complex concepts into understandable, engaging content. Let’s explore the world of tech together

Leave a Comment