Keywords
Operators
Data types
Weird stuff
The only reason you should choose anything in this category is to flex on everyone else and show off your extensive knowledge of Python's weird quirks
100

Which keyword is used to define a function?

def

100

print("6" + "9")

"69"
100

What data type stores key-value pairs?

dictionary (dict)
100

print(True + False)

1

100

t = #code here

print(t) # (1)

What should go in #code here such that printing t returns a tuple with one element (1) in it?

(1,)

200

Which keyword is used to perform more checks after an initial if statement?

elif

200

How can

x = x + 2

be rewritten to be more concise?

x += 2

200

How to add something to the end of a list?

The .append() function

200

How to print the reverse of any string s?

print(s[::-1])

200

x = ["welcome", "to", "my", "house"]

y = list(map(str.upper, filter(lambda s: len(s) > 2, x)))

print(y)

["WELCOME", "HOUSE"]

300

Describe what a try-except block does in Python.

The program will try to run everything under the try statement. If any errors occur, the except block can catch them and deal with them.
300

How to calculate 2 to the 30th power?

2 ** 30

300

x = [6, 9, 4, 2]

print(x[:2])

[6, 9]

300

Describe what a for-else statement does:

for ...:

    ...

else:

    ...

The else cause only triggers if the break keyword is not called in the for loop.

300

print(reversed("hi"))

<reversed object>

400

Describe what the continue keyword does in Python.

It is used in loops; it brings the control flow back to the beginning of the loop.

400
What does the // operator do?

Integer division; it divides two values and rounds down to the nearest integer. (Note that this also applies for negative numbers.)

400

x = [6, 9, 4, 2]

y = x.pop(2)

print(y)

4

400

x = 20

print(f"{x} is greater than {x-1}: {x > 20}.")

"20 is greater than 19: False."

400

sentence = ["What", "the", "heck", "is", "this"]

a, *b, c = sentence

print(b)

["the", "heck", "is"]

500

Describe what the yield keyword does in Python

It is used in generators. Generators are functions, but instead of return, they use yield. Generators "lazily" yield information, only doing so when explicitly told to.

500

print(5 ^ 3)

6

500

what is the easiest way to find the number of distinct elements in a list x? (one-liner)

len(set(x))

500

Which of the following is incorrect?

a. [x for x in range(10)]

b. [x for x in range(10) if x > 6]

c. [x*x if x > 6 for x in range(10)]

c. [x*x if x > 6 else x for x in range(10)]

c

500
x = ["why" "no" "commas" "?"]

print(len(x))

1

M
e
n
u