Dayrvia
Py

Python · Practice questions

Try 8 questions on Python, then read the explanations and review the related concepts.

Practice questions

Choose an answer and move to the next question. Grade the last one to see explanations and review links.

8 questions
Q1 What will this print?
items = ["pen", "cup", "book"]
print(items[1])
Q2 Which list is printed?
a = [3, 5, 7, 9]
print(a[:2])
Q3 What sum is printed?
print(sum(range(2, 7, 2)))
Q4 What are x and len(d) afterwards?
d = {"a": 2}
x = d.get("b", 0)
Q5 What is len(a)?
a = [1, 2]
b = a
b.append(3)
Q6 What does a contain?
a = [[2]]
b = a.copy()
b[0].append(3)
Q7 What is x?
def put(n, bag=[]):
    bag.append(n)
    return len(bag)
put(4)
x = put(5)
Q8 What does a subsequent collect(2) return?
def collect(x, bag=None):
    if bag is None:
        bag = []
    bag.append(x)
    return bag
collect(1)
Original practice questions written for Dayrvia.