Python Intermediate Quiz

1. How do you define a function in Python?

a) void myFunc() {}
b) def myFunc():
c) function myFunc() {}
d) myFunc() {}

2. What does `[1, 2, 3][0]` return?

a) 0
b) 1
c) 3
d) Error

3. True or False: Lists in Python are mutable.

a) True
b) False

4. What is the output of `d = {"a": 1}; print(d["a"])`?

a) a
b) 1
c) {"a": 1}
d) Error

5. How do you add an element to a list?

a) list.add(4)
b) list.append(4)
c) list.push(4)
d) list.insert(4)

6. What does `try: x = 1/0 except: print("Error")` do?

a) Prints 1
b) Prints "Error"
c) Crashes
d) Nothing

7. What is `[x * 2 for x in [1, 2, 3]]`?

a) [1, 2, 3]
b) [2, 4, 6]
c) [1, 4, 9]
d) Error

8. True or False: Tuples are immutable.

a) True
b) False

9. What is the output of `print({"a": 1}.get("b", 0))`?

a) 1
b) 0
c) None
d) Error

10. What does `lambda x: x * 2` create?

a) A class
b) An anonymous function
c) A loop
d) A dictionary