Professional Documents
Culture Documents
14th June 23
14th June 23
100
200
300
1
[15]: a = 100
print(a)
b = 200
print(b
c = a + b
print(c)
Input In [15]
c = a + b
^
SyntaxError: invalid syntax
[23]: # since the error has happened at compiled time therefore print(a)
# hasnt worked
# also the error shows at c = a + b because it was expecting maybe the bracket␣
↪closed at next line
[25]: a = 100
print(a)
b = 200
print(b
)
c = a + b
print(c)
100
200
300
[13]: a = 100
print(a)
b = 200
print(b)
c = A + b
print(c)
100
200
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [13], in <cell line: 5>()
3 b = 200
4 print(b)
----> 5 c = A + b
6 print(c)
2
NameError: name 'A' is not defined
[16]: # in this case the byte code will be generated as there is no compilation error
# so line by line will be executed
0.0.3 Python is a case sensitive language means ‘a’ and ‘A’ are diff.
[17]: a = 100
print(a)
b = 200
print(b)
c = A + b
print(c)
d = 10000
print(d)
100
200
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [17], in <cell line: 5>()
3 b = 200
4 print(b)
----> 5 c = A + b
6 print(c)
7 d = 10000
[20]: x = 100
print(x)
y = 0
print(y)
z = x / y
print(z)
100
0
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
Input In [20], in <cell line: 5>()
3
3 y = 0
4 print(y)
----> 5 z = x / y
6 print(z)
[22]: x = 100
print(x)
y = 0
print(y)
z = x $ y
print(z)
Input In [22]
z = x $ y
^
SyntaxError: invalid syntax
[27]: a = 100
print(a)
b = 200
print(b)
c = a + b
prin(c)
100
200
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Input In [27], in <cell line: 6>()
4 print(b)
5 c = a + b
----> 6 prin(c)
[32]: 10 + 'a'
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
4
Input In [32], in <cell line: 1>()
----> 1 10 + 'a'
1 Memory Management
• managing the memory => allocating and deallocating the space/memory to and from the
values
• inefficient memory management leads to slowness of the program execution
• In Python, memory management is taken care by Python itself (automatic)
• Python Memory Manager (PMM) is responsible to manage the memory
Memory allocation
1. Static memory allocation
• the memory is allocation is done during compile time
• stack memory is used
• memory cannot be re-used
• int a = 100;
2. Dynamic memory allocation
• the memory allocation is done during runtime
• heap memory is used
• memory can be re-used
• a = 100
• In Python, dynamic memory allocation is used
• The PMM allocates the memory to a value and when the value is not needed, PMM auto-
matically deletes the value from the memory.
• Stack memory: memory allocation happens on continuous memory location
• Heap memory: its a pile of memory (non-continuous). It happens randomly.
• PMM has:
– Raw memory allocator: used to interact with the OS to ensure there is enough memory
– Object Specific allocator: used to allocate the memory to the values/data/objects
• Areas created during memory allocation
[ ]: