Challenge - 5 Problems
Dynamic Typing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this dynamic typing example?
Consider the following Python code that uses dynamic typing. What will be printed?
Python
x = 5 x = 'hello' print(x)
Attempts:
2 left
💡 Hint
Remember, Python variables can change type at any time.
✗ Incorrect
The variable x first holds an integer 5, then it is reassigned to a string 'hello'. The print statement outputs the current value, which is 'hello'.
❓ Predict Output
intermediate1:30remaining
What is the output when changing variable types?
What will this code print?
Python
a = 10 b = a b = 'changed' print(a)
Attempts:
2 left
💡 Hint
Changing b does not affect a because integers are immutable.
✗ Incorrect
Variable a remains 10 because b was assigned the value of a, not a reference that changes a.
❓ Predict Output
advanced2:00remaining
What error does this code raise?
What error will this code produce?
Python
x = 5 x = x + '10' print(x)
Attempts:
2 left
💡 Hint
You cannot add an integer and a string directly.
✗ Incorrect
Adding an integer and a string causes a TypeError in Python because they are incompatible types for addition.
❓ Predict Output
advanced1:30remaining
What is the output of this variable reassignment?
What will be printed by this code?
Python
var = [1, 2, 3] var = 'now a string' print(type(var))
Attempts:
2 left
💡 Hint
The variable var is reassigned to a string.
✗ Incorrect
The type of var after reassignment is str, so printing type(var) outputs .
🧠 Conceptual
expert2:30remaining
Which option best explains dynamic typing in Python?
Choose the statement that correctly describes dynamic typing in Python.
Attempts:
2 left
💡 Hint
Think about whether variables themselves have types or if types belong to values.
✗ Incorrect
In Python, variables are just names that point to values. Values have types, and variables can be reassigned to values of any type at any time.