0
0
Pythonprogramming~20 mins

Assignment and augmented assignment in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of augmented assignment with strings
What is the output of this code?
Python
text = "Hi"
text += " there"
print(text)
Athere
BHi
CHi there
DHi+= there
Attempts:
2 left
💡 Hint
Remember that += adds to the existing string.
Predict Output
intermediate
2:00remaining
Value after augmented assignment with lists
What is the value of the list after running this code?
Python
numbers = [1, 2, 3]
numbers += [4, 5]
print(numbers)
A[1, 2, 3, [4, 5]]
B[4, 5]
C[1, 2, 3]
D[1, 2, 3, 4, 5]
Attempts:
2 left
💡 Hint
+= with lists extends the list by adding elements.
Predict Output
advanced
2:00remaining
Output of mixed augmented assignments
What is the output of this code?
Python
x = 5
x *= 2
x -= 3
print(x)
A7
B10
C16
D13
Attempts:
2 left
💡 Hint
Apply each operation step by step.
Predict Output
advanced
2:00remaining
Error raised by invalid augmented assignment
What error does this code raise?
Python
a = 10
b = "5"
a += b
ATypeError
BNameError
CSyntaxError
DNo error, output is 15
Attempts:
2 left
💡 Hint
You cannot add a string to an integer directly.
🧠 Conceptual
expert
2:00remaining
Effect of augmented assignment on mutable vs immutable types
Which statement is true about augmented assignment (like +=) in Python?
A+= always modifies the object in place regardless of type.
BFor mutable types, += modifies the object in place; for immutable types, it creates a new object.
C+= always creates a new object regardless of type.
DFor immutable types, += modifies the object in place; for mutable types, it creates a new object.
Attempts:
2 left
💡 Hint
Think about lists vs strings and numbers.