# Python Operators

We know that an operator is a symbol which performs an operation. An operator acts upon which data items is known as operands.

Python supports the following operators which are as follows:

• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators

### Python Arithmetic Operators

Arithmetic operators are specifically used with numeric values to perform mathematical operations operations like addition, subtraction, multiplication, division.

# Examples of Arithmetic Operator
x = 5

y = 3

# Subtraction of numbers

sub = x - y

# Multiplication of number

mul = x * y

# Division(float) of number

div1 = x / y

# Division(floor) of number

div2 = x // y

# Modulo of both number

mod = x % y

# print results

print(sub)

print(mul)

print(div1)

print(div2)

print(mod)

Output

8
2
15
1.6666666666666667
1
2

### Python Assignment Operators

Assignment operators are used to assign values to variables:

Example

>>> x=2

>>> x=x+2

>>> x

4

>>> x+=2

>>> x

6

>>> x*=3

>>> x

18

>>> a,b=10,20

>>> a

10

>>> b

20

>>> n=10

>>> n

10

>>> -n

-10

### Python Comparison(Relational) Operators

Comparison(Relational) operators are used to compare two values: Here in this context the output value is a Boolean value(Either True or False).

#Example

>>> a=10

>>> b=20

>>> a<b

True

>>> a>b

False

>>> a==b

False

>>> a<=b

True

>>> a>=b

False

>>> a!=b

True

#Example

>>> a<b and b<10

False

>>> a<4 or b<20

False

>>> a and b

20

>>> a or b

10

>>> not a

False

>>> a= not a

>>> a

False

### Python Identity Operators

Identity operators are used to compare the objects.

# Examples

a1 = 10

b1 = 10

a2 = 'SilanTechnology'

b2 = 'SilanTechnology'

a3 = [10,20,30]

b3 = [10,20,30]

print(a1 is not b1)

print(a2 is b2)

# Output is False, since lists are mutable.

print(a3 is b3)

False
True
False

### Python Membership Operators

• in and not in are the membership operators; used to test whether a value or variable is in a sequence.
• in       True if value is found in the sequence
• not in       True if value is not found in the sequence

# Examples of Membership operator

p = 'SILAN Technology'

q = {10:'x',20:'y'}

print('S' in p)

print('java' not in p)

print('Tech' not in p)

print(3 in q)

print('y' in q)
Output: True

True

False

False

### Python Bitwise Operators

# Examples
x = 5
y = 3

# Print bitwise AND operation
print(x & y)

# Print bitwise OR operation
print(x | y)

# print bitwise XOR operation
print(x ^ y)

# print bitwise right shift operation
print(x >> 2)

# print bitwise left shift operation
print(x << 2)

Output

1
7
6
1
20

### Services

###### College Campus Training Industrial Training Corporate Training Website Designing Website Development Digital Marketing SEO Consultancy

Plot No-741,2ND Floor
Bhubaneswar-751013
Email: info@silantechnology.com
Phone: 0674-2361252