Dynamic Typing in PythonIn this tutorial, we will understand what’s dynamic typing in python. Whenever we write a program in python, we come across a different set of statements, one of them is an assignment statement where we initialize a variable with a value. Let us see how the assignment is different in the case of Python. When we talk about languages like C, C++, and Java the memory is allocated based on the data type of variable and is accessed accordingly whereas python being a dynamically typed language it stores the value at some location and then combines the respective variable name with a container. The data type is determined at the run time. Consider the program given below- Output: <class 'float'> <class 'int'> <class 'str'> 36.0 72 datadatadata Explanation: Let’s have a look at the explanation of this program-
Relationship Between Objects, Variables and References.The following sequence of steps happens when we assign a variable in Python-
Consider the program given below- Output: <class 'float'> <class 'int'> <class 'str'> <class 'complex'> Explanation: Let’s understand what happened in the above program.
Shared ReferencesBefore starting with this, let’s have a look at the program- Output: 12.0 12.0 Explanation: It’s time to understand what exactly happened here-
This is nothing but the concept of shared references which says that “Two variables can have the same reference.” One more example would make it clearer. Output: 84.0 12.0 Explanation: Let’s have a look at the explanation of this program-
The Disadvantage of Dynamically Typed LanguagesThe feature that makes a language like Java more convenient is that it is statically typed and so the bugs and the errors are reported at compile-time instead of run-time. Therefore, it’s a major concern for the python developers that the errors are shown during the run-time and therefore they have to develop strategies to rectify them. ConclusionCulminating the tutorial, we can say that python is a dynamically typed language and here we understood what are the distinct characteristics that can be observed while working on it. |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263386.html