Loops
Lists
Functions
Tracing
100

What Python keyword is used to exit the current iteration of a loop and move to the next one?

continue

100

What is a 2D list?

A list that contains other lists as its elements.

100

What keyword defines a function?

def

100

What does this code produce, and what is the length of nums?


nums = [1, 2, 3]
nums.append([4, 5])


nums = [1, 2, 3, [4, 5]]

200

What Python function is often used in a for loop to repeat a block of code a fixed number of times?

range()

200

What does it mean for a list to be mutable?

List elements can be changed without creating a new list.

200

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.

200

What is the output?

a = [1, 2, 3]
b = a
a.append(4)
print(b)

[1, 2, 3, 4]

300

What Python loop that is guaranteed to execute zero or more times depending on a condition?

while

300

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.

300

What kind of scope do variables inside functions have?

local

300

What is the output of this function call? 

def greet(name="Student"): 

     return f"Hello, {name}!"

greet()

Hello Student!

400

How do you access the element in row 3, column 2 of matrix?

matrix[2][1]

400

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.

400

What value does a function return if there’s no return statement?

none

400

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}

500

What structure is commonly processed with nested loops?

2D lists

500

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

500

What is a default parameter?

A value assigned in the function definition that is used if no argument is provided.

500

nums = [1, 2, 3]
for i in range(len(nums)):
    nums[i] += i
print(nums)

[1, 3, 5]

M
e
n
u