PYTHON and variables?

 PYTON does not work with variables. PYTON works with:
- name,
- objects,
- types,
- values,
- reference number.
If we write:
a = 7
then:
- a is the name
- a PYTHON object corresponding to the name a is created
- 7 is value
- the type is whole
- the reference count is 0.
if we write below
a = 100
then:
- remain the same name,
- a new object associated with the name a is created,
- the type is integer,
- the reference count is 1
This explains the different addresses id (a) from the first assignment and from the second assignment.
Programe is:
a = 7
print(id(a))
a = 100
print(id(a))

Results are:

============== RESTART: /Users/ionivan/Documents/pointerspython.py =============
4408295856
4408298832
If the sequence is considered:
a = 25
b = a
the names a and b correspond to the same object, so they will have the same address.
Programul este:
a = 25
b = a
print("Adress a name is",id(a))
print("Adress b name is",id(b))

Rezultatele sunt:

============== RESTART: /Users/ionivan/Documents/pointerspython.py =============
Adresse a name is 4480173040
Adresse b name is 4480173040

Rorograme is:

list_A = [2, 3, 4, 5, 6, 7, 8, 9, 10]
print("list_A is", list_A)
print("Adresse list_A is", id(list_A))
print("Adresse list_A[8] is", id(list_A[8]))
list_A.append(11)
print("list_A  after append is", list_A)
print("Adress list_A after append is", id(list_A))
print("Adresse list_A[9] is", id(list_A[9]))
list_A.insert(0, 20)
print("list_A  after insert is", list_A)
print("Adress list_A[10] after insert is", id(list_A[10]))

Results are:
list_A is [2, 3, 4, 5, 6, 7, 8, 9, 10]
Adresse list_A is 4363290752
Adresse list_A[8] is 4360651280
list_A  after append is [2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Adress list_A after append is 4363290752
Adresse list_A[9] is 4360651312
list_A  after insert is [20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
Adress list_A[10] after insert is 4360651312

There are big differences between working in C ++ and PYTHON. Programmers who have worked in C ++ use the concept of variable, but in PYTHON it is correct to use names.

(March 31, 2022)

Comments

Popular posts from this blog

Functions and many return parameters

Functions list in PYTHON