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
#1
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!
Reply
#2
(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
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

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  kill python execution program lebossejames 0 182 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  Confused about python execution jpezz 4 1,324 Oct-09-2022, 06:56 PM
Last Post: Gribouillis
  What do i have to type in the IDLE shell to use this password manager program? MaartenRo 4 1,691 Jan-15-2022, 02:01 PM
Last Post: MaartenRo
  how can a variable change if I haven't changed it? niminim 5 2,992 Apr-07-2021, 06:57 PM
Last Post: niminim
  Python Program running a lot slower after change to Ubuntu hubenhau 1 2,841 Mar-02-2021, 05:01 PM
Last Post: Serafim
  type change of dbshelve key between Python 2 and 3 ccaudle 3 2,353 Feb-09-2021, 05:13 PM
Last Post: ccaudle
Question dict value, how to change type from int to list? swissjoker 3 2,691 Dec-09-2020, 09:50 AM
Last Post: perfringo
  Change variable value during a while loop? penahuse 2 3,988 Nov-15-2020, 11:53 PM
Last Post: penahuse
  Change variable in an outside file ebolisa 5 2,568 Nov-11-2020, 04:41 AM
Last Post: ebolisa
  Change name of variable samuelbachorik 2 2,021 Aug-10-2020, 02:34 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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