1/81
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What data structure is immutable?
Tuple
What data structure uses square brackets []?
List
What data structure uses parentheses ()?
Tuple
What data structure stores key-value pairs?
Dictionary
What does len() return?
The number of items in a list, tuple, string, or other collection
What does append() do?
Adds one item to the end of a list
What does extend() do?
Adds all items from another collection to a list
What does remove() do?
Removes a specified value from a list
What does sort() do?
Sorts a list in ascending order
What does reverse() do?
Reverses the order of items in a list
What is indexing?
Accessing elements by their position number
What is the first index in a list?
0
What does a negative index do?
Counts from the end of the list
What does list[-1] return?
The last item in the list
What is slicing?
Selecting a range of elements from a list or string
What does list[start:end] return?
Elements from start up to but not including end
What does range(len(my_list)) allow you to do?
Loop through list indexes
What does % mean in Python?
Modulus (remainder)
What does index % 2 0 check?
If an index or number is even
What does index % 2 1 check?
If an index or number is odd
What is a for loop used for?
Repeating code for each item in a collection
How do you loop through values in a list?
for item in my_list
How do you loop through indexes in a list?
for i in range(len(my_list))
What is a nested loop?
A loop inside another loop
What is a 2D list?
A list containing other lists
How do you access an element in a 2D list?
my_list[row][column]
What does my_list[1][2] mean?
Row 2, column 3
What does my_list[1:3] do?
Returns rows 2 through 3, not including row 4
How can you create a 2D list?
By appending lists into another list
What is a list comprehension?
A shortcut for creating lists
Example of a list comprehension
[i ยท 2 for i in range(6)]
What is packing?
Storing multiple values in a collection such as a list or tuple
What is unpacking?
Assigning multiple variables from a collection
Example of unpacking
a, b, c = [1, 2, 3]
What is a string?
A sequence of characters
What does split() do?
Converts a string into a list
Example of split()
"Hello World".split() returns ["Hello", "World"]
What does join() do?
Converts a list into a string
Example of join()
" ".join(["Hello","World"]) returns "Hello World"
What does "a".join(["b","n","n"]) return?
banan
What is a dictionary?
A collection of key-value pairs
How do you access a dictionary value?
dictionary[key]
What does a dictionary map?
Keys to values
How do you loop through a dictionary?
for key in dictionary
What does compare?
Values
What does is compare?
Object identity (same object in memory)
If two lists contain the same values, what does return?
True
If two separate lists contain the same values, what does is usually return?
False
What file mode is used for reading?
'r'
What file mode is used for writing and overwriting?
'w'
What file mode is used for appending?
'a'
What file mode is used to create a new file only?
'x'
What does read() do?
Reads the entire file as a single string
What does read(size) do?
Reads a specific number of characters
What does readline() do?
Reads one line from a file
What does readlines() do?
Reads all lines and returns a list of strings
What does write() do?
Writes content to a file
What does write() return?
The number of characters written
What does seek() do?
Moves the file pointer to a specified position
What does seek(0) do?
Moves the file pointer to the beginning of the file
What does a positive seek offset do?
Moves the file pointer forward
What does close() do?
Closes an open file
Why should files be closed?
To save resources and ensure changes are written properly
What happens when a file is opened in 'w' mode?
Existing contents are overwritten
What happens when a file is opened in 'a' mode?
New content is added to the end
What does readlines() return?
A list where each element is a line from the file
What type of value does len() return?
Integer
What does print(my_list[3][1:]) do in a 2D list?
Prints elements from index 1 to the end of row 4
What is the output type of split()?
List
What is the output type of join()?
String
What is the difference between append() and extend()?
append adds one item; extend adds multiple items
Can tuples be modified after creation?
No
Can lists be modified after creation?
Yes
Can dictionaries be modified after creation?
Yes
What are the three most tested file-reading methods?
read(), readline(), readlines()
What are the three most common list methods?
append(), extend(), remove()
What are the most common list-processing functions?
len(), sort(), reverse()
What is the most important thing to remember about tuples?
They are immutable
What is the most important thing to remember about dictionaries?
They map keys to values
What is the most important thing to remember about 2D lists?
Use [row][column] indexing
What is the most important thing to remember about file mode 'w'?
It overwrites existing contents
What is the most important thing to remember about file mode 'a'?
It appends to the end without deleting existing content