0
0
Pythonprogramming~20 mins

Variable assignment in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Variable Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of chained assignment
What is the output of this code snippet?
Python
a = b = c = 5
print(a, b, c)
A5 5
B5
C5 5 5
DSyntaxError
Attempts:
2 left
💡 Hint
Think about how Python assigns the same value to multiple variables in one line.
Predict Output
intermediate
2:00remaining
Output after multiple assignments
What will be the value of x after running this code?
Python
x = 10
y = x
x = 20
print(y)
ANone
B20
CNameError
D10
Attempts:
2 left
💡 Hint
Remember that y gets the value of x at the time of assignment, not a reference.
Predict Output
advanced
2:00remaining
Output of tuple unpacking assignment
What is the output of this code?
Python
a, b, c = 1, 2, 3
b, c = c, b
print(a, b, c)
A1 2 3
B1 3 2
C3 2 1
DSyntaxError
Attempts:
2 left
💡 Hint
Look carefully at how tuple unpacking swaps values.
Predict Output
advanced
2:00remaining
Output of augmented assignment with mutable object
What is the output of this code?
Python
lst = [1, 2]
lst2 = lst
lst += [3]
print(lst2)
A[1, 2, 3]
B[1, 2]
CTypeError
DNone
Attempts:
2 left
💡 Hint
Remember that lst and lst2 point to the same list object.
Predict Output
expert
2:00remaining
Output of variable assignment with walrus operator
What is the output of this code snippet?
Python
if (n := 5) > 3:
    print(n * 2)
else:
    print(n)
A10
B5
CSyntaxError
DNone
Attempts:
2 left
💡 Hint
The walrus operator assigns and returns the value in the same expression.