How variable type changes at runtime
📖 Scenario: Imagine you are working with a variable that can hold different types of information during a program. For example, a box that can hold a number first, then a word, and then a list. This shows how Python allows the type of a variable to change as the program runs.
🎯 Goal: You will create a variable and change its type step-by-step, then print its value and type each time to see how it changes.
📋 What You'll Learn
Create a variable called
data and assign it the integer value 10Change the variable
data to hold the string value 'hello'Change the variable
data to hold the list [1, 2, 3]Print the value and type of
data after each change💡 Why This Matters
🌍 Real World
In real programs, variables often change what they hold depending on the situation, like storing a number first and then a message.
💼 Career
Understanding how variables can change types helps in debugging and writing flexible code in many programming jobs.
Progress0 / 4 steps