Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data as relation between objects in Python

Chapter Data Model in the section of Language Reference of Python documentation says:

All data in a Python program is represented by objects or by relations between objects.

I understand the part that all data in Python program is represented by objects. But what data is represented by relations between objects?

Can someone give an example with explanations, please?


1 Answers

But what data is represented by relations between objects?

For example, in

d = {2: 'b'}

the relationship is that the object 2 is mapped to the object 'b' in the dictionary d.

In

l = [2, 'b']

the relationship is that the objects 2 and b are the 0 and 1 members of the list l.

In

class Foo(object):
    def __init__(self, x):
        self._x = x

f = Foo(2)

the relationship is that the object 2 is the member _x of f.

like image 123
Ami Tavory Avatar answered Sep 28 '26 17:09

Ami Tavory



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!