Notebook
April 19, 2025
1 Comparision operation
[ ]: - Comparision operators return Only a boolean value (True or False)
< # less than
<= # lessthan or equals
> # greater than
>= # greater than or equals
[ ]: < # less than
[1]: a = 10
b = 99
[2]: a
[2]: 10
[3]: b
[3]: 99
[ ]: a < b
[4]: 10 < 99
[4]: True
[5]: b < a
[5]: False
[ ]: <= # lessthan or equals
[6]: 100 < 100
[6]: False
[7]: 100 <= 100
1
[7]: True
[ ]: > # greater than
[8]: a
[8]: 10
[9]: b
[9]: 99
[10]: a > b
[10]: False
[11]: b > a
[11]: True
[ ]: >= # greater than or equals
[12]: 100.99 > 100.99
[12]: False
[13]: 100.99 >= 100.99
[13]: True
2 Equality operation
[ ]: # Equality operators return Only a boolean value (True or False)
== # equals
!= # Not equals
[14]: 1000 == 1000
[14]: True
[15]: 200 == 400
[15]: False
[16]: a
[16]: 10
2
[17]: b
[17]: 99
[18]: a == b
[18]: False
[19]: a != b
[19]: True
[20]: str1 = "Hello"
str2 = "hello"
[21]: str1
[21]: 'Hello'
[22]: str2
[22]: 'hello'
[23]: str1 != str2
[23]: True
[24]: str3 = "hello"
str4 = "hello"
[25]: str3
[25]: 'hello'
[26]: str4
[26]: 'hello'
[27]: str3 == str4
[27]: True
[ ]: # ASCII- American Standard Code for Information Interchange
3
[ ]: "Hello"
"hello"
[ ]: 72
[ ]: 104
[ ]: False
[ ]: "hello"
"hello"
[ ]: 104,101 , 108 , 108 ,111
[ ]: 104 , 101 , 108 , 108 ,111
[ ]: True
[ ]: "A"
[ ]: type()
[ ]: # to check ASCII value from a letter
4
[28]: ord("A")
[28]: 65
[ ]: 99
[ ]: # to char value from a ASCII number
[30]: print(chr(99))
[32]: ord("s")
[32]: 115
3 Logical operators
[ ]: True ----> 1
False ---> 0
[ ]: and
or
not
[ ]: and
5
[ ]: False and False
False and True
True and False
True and True
[33]: False and False
[33]: False
[34]: False and True
[34]: False
[35]: True and False
[35]: False
[36]: True and True
[36]: True
[38]: a = 100
b = 500
if a==100 and b==500: # True
print("Begining of the block")
print("a value is 100")
print("b value is 500")
print("End of the block")
print("Out of the block")
Begining of the block
a value is 100
b value is 500
End of the block
Out of the block
6
[37]: True and True
[37]: True
[40]: a = 100
b = 500
if a==100 and b==99: # False
print("Begining of the block")
print("a value is 100")
print("b value is 500")
print("End of the block")
print("Out of the block")
Out of the block
[39]: True and False
[39]: False
[ ]: or
[ ]: False or False
False or True
True or False
True or True
[41]: False or False
[41]: False
[42]: False or True
[42]: True
[43]: True or False
[43]: True
7
[44]: True or True
[44]: True
[ ]: not
[45]: not True
[45]: False
[46]: not False
[46]: True
[47]: a = 5
not a > 3
[47]: False
[48]: a > 3
[48]: True
[49]: not True
[49]: False
4 Assignment Operation
[ ]: = # assignment operator
[50]: a = 500
8
[51]: a
[51]: 500
5 Compound operators
[ ]: i++ Increment operator
i-- Decrement operator
[53]: a = 5
[54]: a
[54]: 5
[56]: a = a+1 # a+=1
[55]: 5+1
[55]: 6
[57]: a
[57]: 6
[58]: a = a+1 # a+=1
[59]: a
[59]: 7
[60]: a = a-5 # a-=5
a
[60]: 2
[61]: a+=8
[62]: a
[62]: 10
[ ]: a = 5
a = a+5 # a+=5
a = a-5 # a-=5
a = a*5 # a*=5
a = a/5 # a/=5
a = a//5 # a//=5
9
a = a%5 # a%=5
a = a**5 # a**=5
6 Identity operator
[ ]: # it will check the addresses
# It will retur True or False only
- is
- is not
[64]: a = 10
b = 20
c = 30
print(a)
print(b)
print(c)
print(d)
10
20
30
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[64], line 7
5 print(b)
6 print(c)
----> 7 print(d)
NameError: name 'd' is not defined
[65]: d
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[65], line 1
----> 1 d
NameError: name 'd' is not defined
[66]: d =
Cell In[66], line 1
d =
^
10
SyntaxError: invalid syntax
7 Memory Reusability / Object reusability
[67]: a = 10
b = 10
[68]: id(a)
[68]: 140733536545496
[69]: id(b)
[69]: 140733536545496
8 limitations of Memory Reusability
[ ]: it is applicable on integers (-5 to 256)
Memory reusability is not applicable on float
Memory reusability is not applicable on complex
Memory reusability is applicable on boolean
Memory reusability is applicable on None
[70]: var1 = 550
var2 = 550
[71]: id(var1)
[71]: 2714025093488
[72]: id(var2)
[72]: 2714025090928
[74]: var1 = -1
var2 = -1
print(id(var1))
print(id(var2))
140733536545144
140733536545144
[77]: var1 = 256
var2 = 256
print(id(var1))
11
print(id(var2))
140733536553368
140733536553368
[78]: # Memory reusability is not applicable on complex
a = 1+2j
b = 1+2j
print(id(a))
print(id(b))
2714025089776
2714025091408
[79]: a = True
b = True
print(id(a))
print(id(b))
140733535419264
140733535419264
[80]: a = None
b = None
print(id(a))
print(id(b))
140733535500240
140733535500240
[81]: a = 50
b = 50
print(id(a))
print(id(b))
140733536546776
140733536546776
[82]: a is b
[82]: True
[83]: var1
[83]: 256
[84]: var2
[84]: 256
12
[87]: abc = 1.002
lmn = 1.002
print(id(abc))
print(id(lmn))
2714004205104
2714025093232
[88]: abc is lmn
[88]: False
[89]: abc is not lmn
[89]: True
[90]: a = 50
b = 50
print(id(a))
print(id(b))
140733536546776
140733536546776
[92]: print (id(a) is id(b))
False
[102]: address_a = id(a)
[100]: address_b = id(b)
[103]: print(address_a is address_b)
False
[97]: print(140733536546776 is 140733536546776)
True
<>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
<>:1: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
C:\Users\Lenovo\AppData\Local\Temp\ipykernel_3816\3745895525.py:1:
SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
print(140733536546776 is 140733536546776)
[96]: id(140733536546776)
[96]: 2714025092720
[94]: id(140733536546776)
13
[94]: 2714025092528
[ ]: a=5
b=10
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
14
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
[ ]:
15
[ ]:
This notebook was converted with convert.ploomber.io
16