What does value mean in relation to python objects?

I read a link to the python language and the third chapter, “Data Model,” says that every object has an identifier, type, and value. I understood the identity. The type that I assume means the object that is referenced __class__(please correct, if not). I assume that this value means the attributes of an object, or, in other words, the objects referenced by names in the object namespace. Is it correct?

+4
source share
1 answer

Yes, it's right. In most cases, just think of value as the object itself.

You can also use the word “state” to describe the value of an object; for mutable objects, the value can change, but in general, the object, type and identifier do not change.

Some examples:

  • 2048- this is intwith an integer value of 2048. intis an immutable type, so the value will never change. Usually you create a new object of the same type with a different value; 2048 + 1creates a new object intwith a value of 2049 with a new identifier.
  • [42]is a list with a single reference to another object. You can change the content by changing the value of the list. But personality and type would not change.
  • For class instances, Python __class__is writable, allowing you to dynamically change the type. This is rarely necessary, but an option exists.
+3
source

Source: https://habr.com/ru/post/1682200/


All Articles