Variables and Objects¶
Let us get an overview about variables and objects in Python. In Python we need not define data types for variables or objects.* Data types are inherited based up on the values assigned to the variables.
- We can check the type of the variable or object using
- Python is interpreter based programming language which means it does not go through compilation and hence data types are not validated until run time.
- Python variables or objects are dynamically typed. In case of compiler based programming languages such as Java, Scala etc variables or objects are statically typed.
- We can specify data types for variables or objects starting from Python 3. However it is only informational and does not enforce.
i = 10
type(i) == int
- Starting from Python 3 we can specify the data type for the variables or objects.
- However it is not enforced
j: int = 10 # You can specify data type starting from Python 3
j: int = 'Hello' # I am able to assign string to j even though data type is specified as int
type(j) == str