📍📍 Theory of Operators 📍📍
Arithmetic operators
Comparison operators
Logical operators
Let’s initialize a few variables
In [41]:
a = 15 # int
b = 8 # int
c = 15.5 # float
s = 'Hello' # String
📍📍 Arithmetic Operator 📍📍¶
- ‘+’ Addition
- ‘-‘ Subtraction
- ‘*’ Multiplication
- ‘/’ Division
- ‘%’ Modulus
- ‘**’ Exponential
- ‘//’ Floor Division
Addition and subtraction:
In [42]:
a+b
Out[42]:
23
In [43]:
b-a
Out[43]:
-7
Division and multiplication:
In [44]:
a/b
Out[44]:
1.875
In [45]:
a*b
Out[45]:
120
Exponential:
In [46]:
2**3
Out[46]:
8
Floor division and modulo:
In [47]:
a//b
Out[47]:
1
In [48]:
a%b
Out[48]:
7
//
gives the quotient and %
gives the reminder of a division
📍📍 Comparison operators:
¶
- ‘==’ Equal
- ‘!=’ Not equal
- ‘>’ Greater than
- ‘<‘ Less than
- ‘>=’ Greater than or equal to
- ‘<=’ Less than or equal to
In [49]:
a==b
Out[49]:
False
In [50]:
a != b
Out[50]:
True
In [51]:
a == 51
Out[51]:
False
In [52]:
type(a == b)
Out[52]:
bool
In [53]:
a>b
Out[53]:
True
In [54]:
a < b
Out[54]:
False
In [55]:
a>51
Out[55]:
False
In [56]:
a>=51
Out[56]:
False
In [57]:
(1 == 1) and (2 == 2)
Out[57]:
True
In [58]:
(1 == 1) or (3 == 4)
Out[58]:
True
In [59]:
(1 <= 2) or ((2 > 3) or (4 == 4))
Out[59]:
True
In [ ]: