Objects in Python

Python Methods and Functions

Objects are the basic entity in Python

Objects in Python are an abstraction over data: any data is represented here by objects. 


For a description of the object type, see the page “ object (object) ".

Examples of objects in the language:

  • Instances of user-defined and built-in types;
  • The types themselves;
  • Bytecode;
  • Modules;
  • Functions;
  • etc.


At the CPython level, objects are described using the basic structure PyObject.

Objects have three basic (inherent) characteristics:

Identifier The entity that characterizes the object is unchanged throughout the entire period of the object's existence. You can think of it as the address of the object in memory. The identity of two objects (in fact, the equality of identifiers) can be checked using the is operator. You can get the object identifier using the id () function.
Type The datatype defines the abilities of its objects and the possible values ​​for them. Like an identifier, a type remains unchanged throughout the entire lifetime of an object. You can get the type of an object by calling type () with one argument.  A type is also an object, which also has a type of type.
Value If the value object can change, then the object is called mutable , if it cannot - immutable Mutability is determined by type: so numbers, strings and tuples are immutable, while dictionaries and lists are are mutable.

> container containing a reference to a mutable object can of course change when that object changes. However, the container itself is nevertheless considered immutable, because the identity of the mutable object does not change (for example, a tuple may well contain [a reference to] a mutable object). 

Get Solution for free from DataCamp guru