Python Forum
Python - change variable type during program execution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - change variable type during program execution
Why python allows to change the type of a variable during program execution.
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs


Possibly Related Threads…
Thread Author Replies Views Last Post
  Change variable value during a while loop? penahuse 2 119 Nov-15-2020, 11:53 PM
Last Post: penahuse
  Change variable in an outside file ebolisa 5 142 Nov-11-2020, 04:41 AM
Last Post: ebolisa
  Change name of variable samuelbachorik 2 257 Aug-10-2020, 02:34 PM
Last Post: deanhystad
  How to to tie the execution of one process to another inside a loop in Python ignorant_wanderer 0 305 Jul-11-2020, 03:44 AM
Last Post: ignorant_wanderer
  check pandas variable type cools0607 3 402 Jun-12-2020, 09:28 AM
Last Post: buran
  How to find and change variable values ​​in memory thiagoD 1 397 Jun-08-2020, 03:45 AM
Last Post: bowlofred
  trying to change variable value with a def pythonbegginer 11 1,329 Mar-07-2020, 02:54 PM
Last Post: pythonbegginer
  Type hinting - return type based on parameter micseydel 2 504 Jan-14-2020, 01:20 AM
Last Post: micseydel
  "Illegal variable name" message shown when trying to compile program thesurya7 2 841 Apr-19-2019, 08:13 AM
Last Post: thesurya7
  How to get memory usage and execution time of each line in python SriRajesh 2 868 Mar-07-2019, 12:59 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020