Is Python Dynamically Typed Language?

PythonServer Side ProgrammingProgramming

Yes, it is. Python is a dynamically typed language. What is dynamic? We don't have to declare the type of variable while assigning a value to a variable in Python. Other languages like C, C++, Java, etc.., there is a strict declaration of variables before assigning values to them.

Python don't have any problem even if we don't declare the type of variable. It states the kind of variable in the runtime of the program. So, Python is a dynamically typed language. Let's see one example.

Example

 Live Demo

## assigning a value to a variable
x = [1, 2, 3]
## x is a list here
print(type(x))
## reassigning a value to the 'x'
x = True
## x is a bool here
print(type(x))

If you run the above program, it will generate the following results.

Output

<class 'list'>
<class 'bool'>
raja
Published on 08-Jul-2019 13:36:49
Advertisements