0% found this document useful (0 votes)
12 views8 pages

Understanding Python Variable Assignment

The document outlines the process of variable assignment and name resolution in Python, detailing how the interpreter handles names in the symbol table. It describes the steps taken when a name is encountered, including looking it up, returning its value if found, or raising a NameError if not. Additionally, it illustrates memory management and reference counting associated with variable assignments.

Uploaded by

rupeshonlineexam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views8 pages

Understanding Python Variable Assignment

The document outlines the process of variable assignment and name resolution in Python, detailing how the interpreter handles names in the symbol table. It describes the steps taken when a name is encountered, including looking it up, returning its value if found, or raising a NameError if not. Additionally, it illustrates memory management and reference counting associated with variable assignments.

Uploaded by

rupeshonlineexam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

7 10

print n n 25k Name Addr

Iif n ask

C console
window

y
General Syntax to use
any algorithm
Algorithm Name one or more input

call operator
S print IO
70
s print 3.14
3 ly

Print True
True

n 10

print
10
n
LHS sense Assign an object to variable name

Rns sense Use the existing object which has


been named
Steps Python takes when it encounters any name on RHS.

1) Look up for that name in the SYMBOL TABLE.

2) Case 1: Found: Get the base_address of the associated object object and return its value.

3) Case 2: Not found: raise NameError exception emitting error message:


Name 'name' is not de ned.

Exception: Irrecoverable error condition.


>>> print(m)
NameError: Name 'm' is not de ned.

[a-z] or [A-Z] or _

n1
1n

number_1
_number_2

number_of_times

>>>print(True)
True
>>>print(true)

def , class , if , else , if else True

true
Assignment statement : Scenario 2:
n
n = 10
SEE
Tilson
m=n I Tok
70 70
Id I
After Rts before After
Id 11 ties of Stl stint 1

motion 121381
After strut 2

id n

id at object 18mA of id rat object at base addn


return ant
d Cosi

10
2
G id yoseshwar

D n 10
s id h

SS Men

idim
Sang
s
option I
2 10

man
Ctrite Ctrl tr

option 2
n I 25k
M
Ifk
no
Man

ME 10
ME 1 2 33 U
K M

F K

me rise
Ken
F n Inside Python
M 10 V M
mas
EYES
n so

m 5200 m

K 1050
k
j
7 2
I i 22

y m

I 2

Z K
E
I 2
SCENARIO 38

N 10
PROGRAM MEMORY
n 15 Sk
int Name Addr
70

RAM
After RHS of Stm 1
and be for Lhs of strut 1

PROGRAM MEMORY

inter
78 Name Addr
N 8k

RAM
After stmt 12
D PROGRAM MEMORY
n
y8k rak
int
TO 0 Name Addr
15 n 8k

RAM After RHS and before Lhs of Stutz


DID 8k Check if i
n

in Symbol
is

present
Table or not

I Mes
h has been used on

Lies for the first time

I
Create new symbol
table
entry
In
dd
15 new adder
1 gk
Check if n is
present in the

8mm tape
Mf
2 Base Add r in
symbol tablet old add r
ii Current RHS
Base Addry new add
iii In symbol table entry of n

replace old addr by new adder

F the
ix Increment Ref count of new add r

1
by
9k

É
Y Decrement Ref count of old addu by l
8k

You might also like