What is dynamic typing in Python and how it is different from Static typing

Shilpa Sreekumar
3 min readAug 30, 2020

In python, variables are the reserved memory locations to store values. Python is a dynamically typed language which is not required to mention the type of variable while declaring. It performs the type checking at run time. Perl, Ruby, PHP, JavaScript are some examples of dynamically typed programming languages.

Dynamic typing is a key feature of Python, and it refers to the ability of variables to change their data type during runtime. In dynamically-typed languages like Python, you don’t need to explicitly declare the data type of a variable when you define it; instead, the data type is determined at runtime based on the value assigned to the variable. This allows for greater flexibility and ease of use, but it can also lead to potential runtime errors if not used carefully.

Example:

message = "Hello World"
print(message)

#output
Hello World

#Here, the variable msg contains a string value "Hello World". It is not mandatory to mention the type of msg as string which will decided at runtime.

If we want to know the type of the variable message, the code will be:

message="Hello World"
print(message)
print(type(message)) #Type checking

#Output
Hello World
< class 'str' >

One more feature of dynamically typed language is that it is simple to reassign the variable with other datatypes.

--

--