Everything is an object
In Python, all values are (in a sense) objects.
Unlike Java, even basic data types like int
and float
are objects.
So 356
, 3.2
, 4+5j
, "Imperial"
, False
are all objects.
Do you not believe me? Try these:
>>> isinstance(2020, object)
>>> isinstance(4.33, object)
>>> isinstance(5j, object)
>>> isinstance(True, object)
>>> isinstance("COVID-19", object)
Therefore, the following are actually object constructors for the respective built-in type, that takes in some input and creates an instance of the type from the input (if valid). Try each of the following (and note the default values).
>>> int()
>>> float()
>>> complex()
>>> bool()
>>> str()
>>> int(-9.789)
>>> float(9)
>>> float("nan")
>>> float("inf")
>>> float("-inf")
>>> complex(1,2)
>>> bool(1)
>>> bool("")
>>> str("Hello")
>>> str(10)