0
0
Pythonprogramming~5 mins

List mutability in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does it mean that lists in Python are mutable?
It means you can change, add, or remove items in a list after it is created without making a new list.
Click to reveal answer
beginner
Which of these operations changes a list in place?
my_list = [1, 2, 3]
Operations like my_list.append(4) or my_list[0] = 10 change the list without creating a new one.
Click to reveal answer
intermediate
What happens if you assign a new list to a variable that held a list before?
The variable now points to a new list. The old list stays unchanged unless other variables also point to it.
Click to reveal answer
beginner
True or False: Strings in Python are mutable like lists.
False. Strings are immutable, meaning you cannot change them after creation, unlike lists.
Click to reveal answer
intermediate
How does list mutability affect function arguments when you pass a list?
If you change the list inside the function, the change affects the original list outside the function because both refer to the same list.
Click to reveal answer
Which method changes a list by adding an item at the end?
Areplace()
Bappend()
Cinsert_at_end()
Dadd()
What will this code print?
lst = [1, 2, 3]
lst[1] = 5
print(lst)
A[1, 2, 3]
BError
C[5, 2, 3]
D[1, 5, 3]
If you do new_list = old_list and then change new_list, what happens to old_list?
Aold_list changes too
Bold_list stays the same
Cold_list is deleted
DError
Which of these types is immutable in Python?
Alist
Bdictionary
Cstring
Dset
What does mutability allow you to do with a list?
AChange its contents without making a new list
BPrevent any changes to the list
CMake the list read-only
DConvert the list to a string automatically
Explain what list mutability means and give an example of changing a list item.
Think about how you can change a list after you create it.
You got /3 concepts.
    Describe how passing a list to a function can lead to changes outside the function.
    Consider what happens if you add or remove items inside the function.
    You got /3 concepts.