How to use this quiz

Answer each question in your head before expanding the answer. Aim for 20+ out of 25 before moving past the beginner lessons. If a topic trips you, its lesson is linked in the explanation. The Coding Python app has a longer 112-question version with scoring and per-topic tracking.

Variables, types and operators

1. What does print(type(3 / 1)) output?

<class 'float'>. The / operator always returns a float. Use // for integer division. — Operators

2. What is the value of 7 // 2 and -7 // 2?

3 and -4. Floor division rounds toward negative infinity.

3. What does bool("False") return?

True. Any non-empty string is truthy regardless of its content.

4. What is 2 ** 3 ** 2?

512. Exponentiation is right-associative: 2 ** (3 ** 2) = 2 ** 9.

5. Which of these is a valid variable name: 2nd, my-var, _total, class?

Only _total. Names cannot start with a digit, cannot contain hyphens, and class is a keyword. — Variables

Strings

6. What does "Python"[1:4] give?

"yth". Slicing starts at index 1 and stops before index 4.

7. What does "a,b,,c".split(",") return?

['a', 'b', '', 'c']. Consecutive separators produce empty strings.

8. What is printed by s = "hi"; s.upper(); print(s)?

hi. Strings are immutable; upper() returns a new string that was discarded. — Strings

9. What does f"{3.14159:.2f}" produce?

"3.14". The format spec .2f means two decimal places, fixed-point.

Control flow and loops

10. How many times does for i in range(2, 10, 3) loop?

Three times: i = 2, 5, 8.

11. What does the else clause of a for loop do?

It runs after the loop finishes normally, but not if the loop exited with break. — Loops

12. What is the output?
x = 5
if x > 3: print("a")
elif x > 4: print("b")
else: print("c")

a. Only the first true branch runs; the elif is never checked. — if/else

13. What does continue do inside a loop?

Skips the rest of the current iteration and moves to the next one. break leaves the loop entirely.

Lists, tuples, dicts and sets

14. What does a = [1, 2]; b = a; b.append(3); print(a) print?

[1, 2, 3]. b is another name for the same list, not a copy. — Lists

15. What is [1, 2, 3].sort()?

None. sort() works in place and returns None. Use sorted() to get a new list.

16. What does len({1, 2, 2, 3, 3, 3}) return?

3. Sets contain unique values only.

17. What happens with d = {}; print(d["x"])?

KeyError: 'x'. Use d.get("x") to get None instead. — Dictionaries

18. What is type((1)) versus type((1,))?

int and tuple. Parentheses alone do not make a tuple; the comma does.

19. What does [x * 2 for x in range(4) if x % 2] produce?

[2, 6]. Only x = 1 and 3 pass the filter (non-zero remainder), then doubled.

Functions, classes and exceptions

20. What does a function return if it has no return statement?

None. — Functions

21. Why is def f(items=[]) a bug?

The default list is created once and shared across every call, so items appended in one call appear in the next. Use items=None and create the list inside.

22. What does *args collect?

Extra positional arguments, as a tuple. **kwargs collects extra keyword arguments as a dict.

23. What is self?

The instance on which a method is called. Python passes it automatically as the first argument. — Classes

24. Which block always runs: except, else or finally?

finally. It runs whether or not an exception occurred. — Exceptions

25. What exception does int("3.5") raise?

ValueError. The string is not a valid integer literal; int(float("3.5")) works.

Take the full 112-question quiz in the app — the Coding Python app runs real Python 3 on your phone, with examples, quizzes and challenges built in.
Get it free

Scoring

  • 22–25: solid. Start on projects.
  • 15–21: revisit the linked lessons for the ones you missed, then retake in three days.
  • Under 15: work through the Learn Python course in order; these questions map directly onto it.

Frequently asked questions

Where can I take a longer Python quiz?

The Coding Python Android app includes 112 multiple-choice questions organised by topic, with instant explanations and progress tracking.

Are these questions good for interviews?

They cover the fundamentals interviewers use to screen beginners: mutability, truthiness, slicing, default arguments and exception flow.

How often should I quiz myself?

Same day as learning a topic, then three days later, then a week later. Spaced retrieval roughly doubles retention compared with re-reading.