Loops & Lists
Function Fundamentals
Functions (specified)
Basic Data Structures
File I/O
100

What is a 2D list?

A list that contains other lists as its elements.

100

What keyword defines a function?

def

100

How many values can a function return?

0 to n

100

Which data structure is ordered and immutable?

Tuple

100

This mode in open() will create a new file for writing and overwrite an existing file.

"w" (write mode)

200

What structure is commonly processed with nested loops?

2-D lists

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.

ACCEPT ANY (OTHER) VALID BENEFITS

200

What's the difference between a parameter and an argument?

A parameter is the variable in the function signature/definition, and an argument is the value you pass to that parameter. 

200

What is the main difference between a list and a tuple?

lists are mutable, tuples are not

200

This Python method allows you to remove the newline character from the end of a string when reading from a file.

rstrip()

300

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

matrix[2][1]

300

What kind of scope do variables inside functions have?

local

300

What do you call a parameter with a default value?

an optional parameter

300

Which set operation combines all elements from two sets a & b, but removes duplicates?

a | b


300

Explain why you should not rely on Python automatically closing files at program termination.

Because if the program crashes unexpectedly, buffered data may not be written to the file, resulting in data loss.

400

How can you safely modify a list while 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

Which keyword lets an inner function change a variable that belongs to its outer function?

nonlocal

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}

400

Which mode in open() creates a file if it doesn’t exist but adds to it if it does?

"a" - append mode

500

What is the difference between :

for i in range(len(lst))  

for item in lst?

The first gives indices

the second gives the elements directly

500

What is a default parameter value?

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

500

What is the output of this function call? 

def greet(name="Student"): 

     return f"Hello, {name}!"

greet()

Hello Student!

500

What is the output?

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


[1, 2, 3, 4]

500

Describe the differences between .write(), .writelines(), and print(..., file=...) when writing to a file in Python.

  • .write() writes a single string and does not add a newline automatically.

  • .writelines() writes a list of strings as-is and no newlines are added unless included in the strings.

  • print(..., file=...) writes strings with a newline by default and can be redirected to a file using the file parameter

M
e
n
u