J
J
Jungles2020-08-11 11:53:45
Python
Jungles, 2020-08-11 11:53:45

Storing a reference to objects?

It is very convenient to store data about objects (when there are a lot of them) using a list.
let's say we need to draw many dots in a tkinter module

point_id = []
while True:
    id1 = canvas.create_oval(x,y,x,y, ..........)
    point_id.append(id1)


I just don't quite understand how it works.

If we call point_id, we get a list of objects of type int (which for some reason start with 3)

1) Seriously, why are references to objects stored as a number?
2) we constantly create an object with the same name id1, is it really possible? Or is there a link binding?
that is, the name is the same, but the objects are different
3) why does the iterator, passing through the list, work with objects, and not with numbers. of which this list consists?
It somehow looks very implicit.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-08-11
@Jungles

1) Seriously, why are object references stored as a number?

The developer wanted
2) we constantly create an object with the same name id1, is it really possible? Or is there a link binding?

You don't create an object named id1, you assign a number to id1, which you then store in a list. Variables can be changed, obviously
3) why does an iterator, passing through the list, work with objects, and not with numbers, of which this list consists?

What?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question