Welcome To
Operators



Meaning

The operators is a symbols that tell to python interpreter to do specific task . and those operator need some Operands that is value. many operator perform some mathematical operations and manipulation.

Types

  1. Arithmetic operators
  2. Relational operators
  3. Logical operators
  4. Membership operators
  5. Bitwise operators
  6. Identity operators
  7. Assignment operators

Arithmetic operators

The arithmetic operators to form a mathematical operations like addition , subtract , multiplication, division, modules

Description operators
Addition +
Subtraction -
Multiplication *
Exponent **
Division /
Floor Division //
Modules %

Operators Explanation
Addition(+) The addition adds the two Operands and returns the value it is a type of mathematical operator
Subtract (-) The subtract operator is Subtract the two operands and returns the value or result
Multiplication (*) The multiplication is multiply the two operands and returns the value and result.
Exponent(**) The Exponent operator is used to find the power value 32 and returns the value
Division (/) The division operator is use to divide the two operands and return the value
Floor Division The floor division is like a divide the two operands and returns the value It is just like a Integer and returns the value without fractional point value

Examples

x=10
y=5
print(x+y)
print(x-y)
print(x*y)
print(x**y)
print(x/y)
print(x//y)


output


Relational Operators

The relational operator is used to form a relational expressions and result is boolean value either true or false and this is also called comparison operators mainly used for evaluate Conditional expressions

Description Operators
Less then <
Greater then >
Less then or Equal <=
Greater then or Equal >=
Equal =
Double Equal ==
Not Equal !=

Example

x=10
y=5
print(x>y)

print(x<=y)
print(x<=y)
print(x>=y)
print(x=y)
print(x==y)
print(x!=y)


output

Output

Logical Operator

The logical operator is combination of two or more relational operator . It is also used find the conditional expressions. The value should be either true or False boolean value AND OR NOT

Description Operators
Logical AND And
Logical OR Or
Logical Not !

Example

x=10
y=5
print(x>y And x=y)
print(x<=y Or x=y)
print(x!=y)


output

Assignment Operators

The assignment operator is used to put or assign value to the variable by using = (equal) abs lift-side operand is assigned to the right-side operand that is shown in the below . but the python provides the short hand assignment operator . like += -= etc
syntax operand mathematical operator = value

Operators

Operator Explaination Example
=
The equal operator assigned the value of lift-side operand from right-side operand that is shown in example a=10
b=a
print(a)
print(b)
output:10
10
+=
The += it adds the value of two operand and the value assigned in left-side operand that is shown in example a=10
b=10
a+=b
print(a)
output:20
-=
The -= it subtract the value of two operand and the value assigned in left-side operand that is shown in example a=10
b=5
a-=b
print(a)
output:5
+=
The += it adds the value of two operand and the value assigned in left-side operand that is shown in example a=10
b=10
a+=b
print(a)
output:20
*=
The *= it multiply the value of two operand and the value assigned in left-side operand that is shown in example a=10
b=5
a*=b
print(a)
output:50
/=
The /= it divide the value of two operand and the value assigned in left-side operand that is shown in example a=10
b=10
a/=b
print(a)
output:0
%=
The %= it divides the value of two operand and the value assigned in left-side operand that is shown in example a=10
b=5
a%=b
print(a)
output:5

Bitwise Operators

The bitwise Operators in python is perform the bt level and binary bit operations . The python bitwise operator is performs a individual bits at the bit level the Examples shown below

Operators Explanation Example
&
Bitwise AND(&) operator is performs individual bits if same place 1 having then the output is 1 other wise 0. a=5#0101
b=3#0011
print(a&b) output:1 #0001
|
Bitwise OR(|) operator is performs individual bits if same place 0 having then the output is 0 other wise 1. a=5#0101
b=3#0011
print(a|b) output:7 #0111
^
Bitwise XOR(^) operator is performs individual bits if same place 0 having then the output is 0 and same place having 1 then the output is 0 if different number bits output is 1. a=5#0101
b=3#0011
print(a^b) output:6 #0110
<<
Bitwise Left-shipt(<<) operator . The left operand value is shifted left by the number of bits given in the right operand . a=0101
print(a<<<2)
output:20
>>
Bitwise Left-shipt(>>) operator . The left operand value is shifted left by the number of bits given in the right operand . a=0101
print(a>>2)
output:1

Membership Operators

The membership operator is used to check the particular element is particular sequence such as string ,array,list,tuple etc there are two types in and not in.

In

a=[1,2,3,]
3 in a
True

Not In

a=[1,2,3]
3 not in a
False

Identity Operator

The python offers the two types of identity operators is or not is if the variable having the same value it shown in the below example

IS

name="darshan"
myName="darshan"
name is myname
True

NOT IS

name="darshan"
myName="darshan"
name Not is myname
False