Professional Documents
Culture Documents
Day 6
Day 6
-----
Operators
-------------
Operators is a symbol that performs certain operations
python provides the fallowing set of operators
1.Aritmetic operators
2.Relational operators or comparision operators
3.logical operators
4.bitwise operators
5.assignment opertors
6.special operators
#Arithmetic operators
'''
+ --> addition
- --> subtraction
* --> multiplication
/ -->division
% --> modulo
// -->floor division
** --> exponent or power
'''
a=10
b=2
print('a+b',a+b)
print('a-b',a-b)
print('a*b',a*b)
print('a/b',a/b)
print('a%b',a%b)
print('a//b',a//b)
print('a**b',a**b)
eg;
a='sagar'
#b=10
b='10'
print('a+b',a+b)
a=5
b='sagar'
print('a*b',a*b)
#2.Relational operator
-------------------------
# >,>=,<,<=
a=10
b=2
print('a>b',a>b)
print('a>=b',a>=b)
print('a<b',a<b)
print('a<=b',a<=b)
task: check out for strings and bool wrt to relational operators
print(10<20>30<40)
Note:chaining of relational operator is possible where if all the results are true
then end result
will be true else it will be false
a=10
b=2
print('a==b',a==b)
print('a!=b',a!=b)
print(10!=20) #true
3.Logical opertors
--------------------
The logical operators are :
and or not
eg;
print(False and False)
print(False and True)
print(True and False)
print(True and True)
eg;
print(False or False)
print(False or True)
print(True or False)
print(True or True)
eg;
print(not False )
print(not True)
x and y
--------
if x is evalutes to false return x otherwise return y
eg;
#if x is evalutes to false return x otherwise return y
print(10 and 20)
print(0 and 20)
print('subbu' and 'anu')
print("" and 'anu')
x or y
--------
if x is evalutes to true return x otherwise return y
#print(10 or 20)
#print(0 or 20)
#print('subbu' or 'anu')
print("" or "anu")
not x;
---------
if x is false then result is true else result is false
eg;
#not
print(not 10)
print(not 0)
4.bitwise operators
--------------------
1 byte = 8 bits
1 bit can store either 0 or 1
to be continued>>>>>>>>>>>>>>>>>>>>>....!