Did You Hear? Everything’s An Object!
Referring to Python of course ;)
--
In Python… everything is an object! Which makes sense as Python is an object-oriented programming language. If you don’t know what an object is, it’s basically a collection or an encapsulation of data, like variables, and methods, which are functions.
If you make an object, you may need to identify it and there’s multiple ways to do so. Lets say you want to know what kind of object a certain variable was. In order to figure out what type of object this is, you can use the type() function. This is not to be confused with the id() builtin function, which can also help identify an object. But instead of returning the type, the identity is returned. This identity is a long number that is unique and sticks with with the object for it’s entire lifespan.
In Python, objects are either mutable or immutable. Mutable objects store a collection of data that can be changed after being created. These objects include lists, sets, and dictionaries. Continuing the example from the photo above, a is a variable for a list. As you can see this list can hold additional data and remain the same object, identified by it’s identity number. After resetting a:
On the other hand, an immutable object like integers, floats, strings, or tuples, have values that can’t be changed once created. If the variable is changed, a new object is created instead. Like if b was an integer that then changed, it would have a new identity like so: