What Python keyword is used to exit the current iteration of a loop and move to the next one?
continue
What is a 2D list?
A list that contains other lists as its elements.
What keyword defines a function?
def
What does this code produce, and what is the length of nums?
nums = [1, 2, 3, [4, 5]]
What Python function is often used in a for loop to repeat a block of code a fixed number of times?
range()
What does it mean for a list to be mutable?
List elements can be changed without creating a new list.
What is one benefit of using functions?
Reusable: allows you to use a function's logic whenever and wherever needed.
OR
Modular: makes debugging easier, because you fix the error in one specific block of code.
What is the output?
a = [1, 2, 3]
b = a
a.append(4)
print(b)
[1, 2, 3, 4]
What Python loop that is guaranteed to execute zero or more times depending on a condition?
while
What is the difference between append() and extend()?
append() adds its argument as a single element at the end of the list, while extend() adds each element of an iterable individually to the list.
What kind of scope do variables inside functions have?
local
What is the output of this function call?
def greet(name="Student"):
return f"Hello, {name}!"
greet()
Hello Student!
How do you access the element in row 3, column 2 of matrix?
matrix[2][1]
How can you modify a list by looping through it?
By iterating over a copy of the list or building a new list instead; this is why we use temp values.
What value does a function return if there’s no return statement?
none
If:
a = {1,2,3,4}
b = {3,4,5,6}
What does print(a & b) return and
what does print(a and b) return?
print(a&b) = {3,4}
print(a and b) = {3,4,5,6}
What structure is commonly processed with nested loops?
2D lists
What is the difference between :
for i in range(len(lst))
for item in lst?
the first one gives indices
the second one gives elements
What is a default parameter?
A value assigned in the function definition that is used if no argument is provided.
nums = [1, 2, 3]
for i in range(len(nums)):
nums[i] += i
print(nums)
[1, 3, 5]