Recall & Review
beginner
What does it mean that Python variables can change type at runtime?
It means a variable can hold a value of one type at one moment, and later hold a value of a different type without errors.
Click to reveal answer
beginner
Show an example where a variable changes from an integer to a string.
x = 5 # x is an integer
x = "hello" # now x is a string
Click to reveal answer
intermediate
Why can Python variables change type at runtime?
Because Python uses dynamic typing, it does not fix variable types when you write code. Types are checked when the program runs.
Click to reveal answer
beginner
What happens if you try to use a variable in a way that doesn't match its current type?
Python will raise an error if the operation is not supported for the variable's current type.
Click to reveal answer
beginner
Can you assign a list to a variable that was previously an integer? Why?
Yes, because Python variables are just names pointing to values. You can assign any type of value to the same variable name.
Click to reveal answer
What type does a Python variable have?
✗ Incorrect
Python variables have the type of the value they currently hold, not a fixed type.
What happens if you assign a string to a variable that was holding an integer?
✗ Incorrect
Python allows variables to change type by assigning a new value of a different type.
Which typing system allows variables to change type at runtime?
✗ Incorrect
Dynamic typing means types are checked at runtime and variables can change type.
If x = 10, then x = 'ten', what is the type of x now?
✗ Incorrect
After assigning 'ten', x holds a string value.
What error occurs if you try to add a number and a string in Python?
✗ Incorrect
Python raises a TypeError when you try to perform unsupported operations between incompatible types.
Explain how Python variables can change their type during program execution.
Think about how Python treats variable names and values.
You got /4 concepts.
Give an example where a variable changes from one type to another and explain what happens.
Use simple types like integer and string.
You got /4 concepts.