You are on page 1of 4

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

#chaining wrt to reational opertors


print(10<20)
print(10<20<30)
print(10<20<30>40)

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

#2.1 Equality operators


----------------------
# == !=

a=10
b=2
print('a==b',a==b)
print('a!=b',a!=b)

print(10!=20) #true

#chaining of equality operator


print(10==10!=20)

3.Logical opertors
--------------------
The logical operators are :
and or not

For boolean valuves types:


---------------------------
and --> if both inputs are true then end result is true
or --> if atleast one input is true then the result is true
not --> complement or reverse of the input

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)

For non-boolean types :


--------------------------
0 means False
non-zero means True
empty string is always treated as False

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

we can apply the fallowing operators bitwise


& | ^ ~ << >>

& --> and operator


| --> or operator
^ --> xor operator
~ --> not operator
<< --> left shift operator
>> --> right shift operator

to be continued>>>>>>>>>>>>>>>>>>>>>....!

You might also like