Python Forum
Python - change variable type during program execution - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python - change variable type during program execution (/thread-25806.html)



Python - change variable type during program execution - ple - Apr-12-2020

Why python allows to change the type of a variable during program execution.
Example:
sample_var = "test"; (type->string)
sample_var = 1; (type->integer)
sample_var = []; (type->list)
Why can the same variable store different types of data?

The first assignment should determine the type of the variable!


RE: Python - change variable type during program execution - buran - Apr-12-2020

(Apr-12-2020, 08:38 AM)ple Wrote: The first assignment should determine the type of the variable!
That's not the case with python - it's dynamically typed language
https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language