Professional Documents
Culture Documents
1 Operators
• Operator are special symbols in python that carry out arithematic or logical computation.
[1]: # Addition
3+5
[1]: 8
[2]: # Subtraction
54 - 46
[2]: 8
[3]: # Multiplication
2*3
[3]: 6
[4]: # Division
8/2
[4]: 4.0
1
• Division -> always gives output as float
[6]: # Floor division --> Quotient
16//5
[6]: 3
[7]: 1
[8]: # power/exponent
10**2
[8]: 100
[9]: # Paranthesis
(2+3) * (5+5)
[9]: 50
[10]: 21.0
[11]: 2
[12]: b = 3.9
c = False
b+c
[12]: 3.9
2
[13]: b = 3.9
c = False
b/c
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
Input In [13], in <cell line: 3>()
1 b = 3.9
2 c = False
----> 3 b/c
a = 10
a
[14]: 10
[15]: id(a)
[15]: 2694075411024
[16]: a = a+1
print(a)
11
[17]: id(a)
[17]: 2694075411056
[19]: a -= 4 # a = a-4
a
[19]: 3
3
• floor division and (//=)
• Exponent and (** =)
[20]: True
[21]: False
[23]: False
[24]: # is equal to
45 == 45
[24]: True
[25]: True
[26]: True
[27]: False
[28]: 45 == 45.0
[28]: True
4
[29]: 'hi' == 'Hi'
[29]: False
[30]: True
[31]: False
[32]: False
[33]: True
[34]: True
[35]: True
5
• – is operator (# is - true if the operands are identical)
• – is not operators(# is not - True if the operands are not identical)
[36]: a = 5
b = 5
print(a is b)
True
[39]: s1 = 'krishna'
s2 = 'Krishna'
print(s1 is s2)
False
[42]: a = 6
b = 8
a is not b
[42]: True
[43]: a = 'venkatesh'
'eh' in a
[43]: False
[44]: True
[45]: a = [1,2,3,4,5,6]
9 not in a
[45]: True
6
• Comparision Operators
• Membership Operators
• Identity Operators
• Logical Operators
• Assignment Operators
[46]: b = (1>2) or (3>=3)
b
[46]: True