In Python — Everything is an object. Each object has an identity, a type, and a value.
So, what is the fuss with identity, type, and value?
We can think of identity as an object’s address in memory.
Here, the id() gives us the identity that we were talking about, which is a unique integer that never changes during the lifetime of an object. We can think of identity as an object’s address in memory. We can check if two objects are the same with is operator.
>>> player_2 = "Pele" >>> player_1 is player_2 # They are not referring the same object False >>> player_copy = player_1 >>> player_1 is player_copy # They are referring the same object True >>> id(player_2) 139780790567984 >>> id(player_copy) 139780790567600
Now, if we want to check the type of these objects, we can use type().
>>> type(age) <class ‘int’> >>> type(player_1) <class 'str'>
The type of an object cannot change. It can be change under control conditions but it is not generally a good idea.
The value of an object can be changed if the object is mutable and if the object is immutable the value of it cant be changed.
And, The value of an object is what the object is holding in it. Here 53 is the value of age and Maradona is the value of player_1 .
Comentarios