Python Forum

Full Version: Python - change variable type during program execution
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
(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%20...20language