Python 3 · Practice test + 10 free questions · Updated November 2026
A Python practice test checks how well you know Python 3: syntax, data types, control flow, lists and dictionaries, functions, classes, exceptions, files, modules, virtual environments and unit testing. Good questions show a short program and ask what it prints, because that proves you understand Python rather than recognise keywords. Python 3.15 is the newest release line, first released on 9 October 2026, and Python 3.12 gets security fixes until October 2028 (scheduled). Below you will find what a good Python programming practice test covers, a 2–3 week study plan and 10 free Python practice questions with answers, with every code snippet run with Python 3.12.
At a glance
| Topic | Python 3 programming |
| Newest release line | Python 3.15 (9 October 2026) |
| Python 3.12 support | Security fixes until October 2028 (scheduled) |
| Python 2 | Sunset on 1 January 2020 |
| Related certifications | PCEP-30-03 and PCAP-31-04 (Python Institute) |
| Exametics set | 6 practice tests, 450 questions |
- Expect code-reading questions: what a snippet prints, what error it raises, and why. This page has 10 free ones with answers.
- Learn Python 3 only. Python 2 gets no fixes at all, not even security fixes.
Source: Python Developer’s Guide: status of Python versions, What’s New in Python 3.15 and Sunsetting Python 2. Checked on 9 November 2026.
What a good Python practice test covers
A good Python practice test covers the everyday language, not trivia: how values behave, how code flows, and how a small program is organised, tested and run.
It should also tell you which Python version it targets. Small details change between releases. For example, the Python 3.15 release notes say Python now uses UTF-8 as the default text encoding, while the Python 3.12 documentation for open() says the default encoding is platform dependent. A question that ignores this can have two right answers.
Core language: syntax, data types and control flow
The first group checks that you can read Python precisely. Questions on numbers often test floor division and the modulo operator with negative values. The Python built-in types documentation says floor division always rounds towards minus infinity, so (-1)//2 is -1, not 0.
Control-flow questions go beyond if and for. The Python tutorial on control flow explains the first two of these common traps, and the built-in types documentation covers the other two:
- Loop
else: theelseclause of a loop runs only if the loop finishes without abreak. range()end point: the end point is never part of the sequence, sorange(10)gives 0 to 9.- Equality and identity:
==tests whether two values are equal, whileistests object identity: whether two names refer to the same object. - Truth values:
None,False, zero of any number type and empty collections such as'',[]and{}count as false in anif.
Data structures: lists, tuples, dictionaries and strings
Many Python test questions turn on how containers share and change data. The built-in types documentation warns that [[]] * 3 does not copy the inner list: it creates three references to one list. Expect questions on slicing, list methods, tuple unpacking, string methods such as split() and join(), and comprehensions.
Dictionary questions check the methods you use daily. According to the same documentation, dict.get() returns None for a missing key instead of raising KeyError, setdefault() inserts the key if it is missing, and since Python 3.7 dictionaries are guaranteed to keep insertion order.
Functions, classes and exceptions
Function questions test arguments and scope. The control-flow tutorial gives an “Important warning”: a default value is evaluated only once, so a list used as a default argument keeps growing across calls. You should also know *args, **kwargs, keyword-only arguments, lambdas and closures.
Class questions centre on attributes. The Python tutorial on classes shows that a mutable class variable is shared by every instance, and that a name such as __spam is changed to _classname__spam by name mangling. Inheritance, super(), properties and special methods such as __str__ also appear.
Exception questions test the order in which blocks run. The Python tutorial on errors and exceptions says the else block runs only when the try block raised nothing, and finally runs whether or not an exception happened. It also notes that a return inside finally overrides the earlier return, and that Python 3.14 and later give a SyntaxWarning for it.
Files, modules, virtual environments and unit testing
The last group checks that you can work on a real project, not just in a console. The table lists what each topic tests and where the official documentation explains it.
| Topic | What the questions test |
|---|---|
| Files | Modes 'r', 'w' (erases an existing file) and 'a' (adds to the end), and with closing the file even after an error |
| Modules and packages | if __name__ == "__main__":, how sys.path finds modules, and that a module is imported only once per interpreter session |
| Virtual environments | Creating one with python -m venv, activating it, and why it is not committed to Git |
| Unit testing | unittest.TestCase, methods whose names start with test, setUp(), assertRaises() and test discovery |
The official sources are the tutorial on input and output, the tutorial on modules, the venv documentation and the unittest documentation.
Exametics practice tests
Python Programming Practice Tests
- 6 practice tests with 75 questions each: 450 questions in total
- Rebuilt for 2026, with every code snippet run with Python 3.12
- Every answer explained, with a hint, and tagged with one of thirteen topic areas
- Timed Exam Mode test
- Lifetime access
30-day refund. Instant access after payment.
Who these Python practice tests are for
These Python practice tests suit anyone who writes Python 3 and wants an honest check of what they know: students, self-taught learners, developers moving from another language, and job seekers before a technical screen.
They are knowledge tests, not the official exam of any certification body. Use them to find weak topics before a course exam, an interview or a certification. The table shows what each level should be able to do.
| Level | What you should be able to do |
|---|---|
| Beginner | Read and predict short programs with variables, numbers, strings, if, loops and range(); use lists and dictionaries; write simple functions. |
| Intermediate | Explain mutable defaults, shared references and scope; write classes with inheritance; handle exceptions with else and finally; read and write files safely. |
| Job-ready | Structure code into modules and packages, work in a virtual environment, write unit tests, and follow the PEP 8 style guide. |
Preparing for a job interview rather than a test? Our guide to Python interview preparation with practice questions and mock tests covers that next step.
On style, the PEP 8 style guide asks for 4 spaces per indentation level, lines of at most 79 characters, lowercase function names with underscores, CapWords class names, and is or is not when you compare with None.
Python certifications: PCEP and PCAP
If you want a certificate as well as the skills, The OpenEDG Python Institute runs the PCEP and PCAP exams. Its entry-level exam is PCEP and its associate exam is PCAP. The facts below come from the official exam pages.
| Item | PCEP-30-03 | PCAP-31-04 |
|---|---|---|
| Level | Entry | Associate |
| Questions and time | 35 questions, 50 minutes | 42 questions, 65 minutes |
| Passing score | 70% | 72% |
| Prerequisites | None | None formally; PCEP-level knowledge recommended |
| Validity | 5 years | 5 years |
| Exam fee | Not published on the exam page | Not published on the exam page |
PCEP’s largest section is data collections (26%), and PCAP’s is object-oriented programming (28.5%), according to the PCEP exam page and the PCAP exam page. A broad Python practice test is a good base for both. Read our guide on getting ready for PCEP with practice tests if you plan to start there.
Next on your Python path
- PCEP Certified Entry-Level Python Programmer practice tests: the natural first certificate once these questions feel easy.
- PCAP-31-04 Certified Associate Python Programmer practice tests: the next level, with a strong focus on classes, modules and testing.
- Python Interview Preparation practice tests: for job seekers who want interview-style questions next.
How to prepare with a Python practice test in 2–3 weeks
Take one practice test first to find your weak topics, then spend two to three weeks fixing them with the official documentation and short programs you run yourself.
- Days 1–2: Baseline and setup Install a current Python 3 release and create a project folder with
python -m venv .venv. Take one untimed practice test and list the topics where you lost marks. - Days 3–6: Core language and data structures Work through numbers, strings, control flow, lists, tuples and dictionaries. For every wrong answer, type the snippet into Python and change one line to see what happens.
- Days 7–10: Functions, classes and exceptions Practise default arguments, scope, class and instance attributes, inheritance and
try/except/else/finally. Write one small class with a test for each method. - Days 11–14: Files, modules, venv and unittest Split a script into a module and a package, read and write files with
with, and run your tests withpython -m unittest. Then take the next Python programming practice test. - Days 15–21: Timed practice and review Take the timed Exam Mode test, review every explanation, and repeat any test where a topic scored lowest. Stop when you can explain why each wrong option is wrong.
Tip
Do not just read the answer to a code question. Run the snippet, predict the output of a changed version, then run it again.
Planning more than one exam?
Going from Python basics to PCEP, PCAP, Django or Flask? The All-Access Pass covers every practice test on Exametics, including all 12 Python practice-test sets and new exams as they are added, with lifetime access. It costs less than buying about six single practice tests.
Free Python practice questions (10 with answers)
Try these 10 free Python practice questions as a short Python quiz before you start a full practice test. They are original multiple-choice sample questions, each on a different topic, with every code snippet run with Python 3.12; the full Exametics Python practice tests have 450 more questions like these, each with an explanation and a hint.
Practice question 1 · Numbers and operators
What does this code print?
print(-7 // 2, -7 % 2)
- A. -3 -1
- B. -4 1
- C. -3 1
- D. -4 -1
Show answer
Answer: B. Floor division rounds towards minus infinity, so -7 // 2 is -4, not -3. Python keeps the rule x == (x // y) * y + x % y, so -7 % 2 is -7 – (-8), which is 1. A and C round the quotient towards zero, which Python does not do. D gets the quotient right but gives the remainder the sign of the left operand; in Python the remainder always has the same sign as the right operand.
Practice question 2 · Lists
What does this code print?
grid = [[]] * 3 grid[0].append(1) print(grid)
- A. [[1], [], []]
- B. [[1]]
- C. [[1], [1], [1]]
- D. It raises an IndexError
Show answer
Answer: C. [[]] * 3 does not copy the inner list; it builds a list holding three references to the same empty list. Appending through grid[0] changes that one list, so all three positions show [1]. A is what you get with [[] for _ in range(3)]. B is wrong because the outer list still has three items. D is wrong because index 0 exists.
Practice question 3 · Functions
What does this code print?
def add(x, items=[]):
items.append(x)
return items
print(add(1))
print(add(2))- A. [1] then [1, 2]
- B. [1] then [2]
- C. [1, 2] then [1, 2]
- D. It raises a TypeError on the second call
Show answer
Answer: A. A default value is evaluated once, when the function is defined, so both calls share the same list. The first call returns [1]; the second appends 2 to the same list and returns [1, 2]. B is what happens with the safe pattern items=None and a new list inside the function. C is wrong because the first print() runs before 2 is added. D is wrong because the call is valid.
Practice question 4 · Control flow
What does this code print?
for n in [3, 5, 8, 9]:
if n % 2 == 0:
print("even", n)
break
else:
print("none")- A. none
- B. even 8 and then none
- C. Nothing, because the else belongs to the if
- D. even 8
Show answer
Answer: D. The else is aligned with for, so it is the loop’s else clause. It runs only if the loop ends without break. Here 8 is even, so the loop prints even 8 and breaks, and the else is skipped. A would be printed only if no number were even. B is wrong because break skips the loop’s else. C is wrong because the else lines up with for, not with the if; and even an if/else would still let the loop print even 8.
Practice question 5 · Dictionaries
What does this code print?
d = {"a": 1}
print(d.get("b"), d.setdefault("c", 3), len(d))- A. It raises a KeyError
- B. None 3 2
- C. None 3 1
- D. 0 3 2
Show answer
Answer: B. get() returns None for a missing key when no default is given, and never raises KeyError. setdefault("c", 3) inserts "c": 3 and returns 3. The arguments are evaluated left to right, so len(d) is already 2. A is wrong because neither method raises. C ignores that setdefault() adds the key. D is wrong because the default for get() is None, not 0.
Practice question 6 · Exceptions
What does this code print?
def f():
try:
print("try", end=" ")
x = int("7")
except ValueError:
print("except", end=" ")
else:
print("else", end=" ")
finally:
print("finally")
f()- A. try except finally
- B. try finally
- C. try else finally
- D. try except else finally
Show answer
Answer: C. int("7") succeeds, so no exception is raised. The except block is skipped, the else block runs because the try block finished without an error, and finally always runs last. A would need a failing conversion such as int("seven"). B leaves out the else block. D is impossible: except and else never both run for the same try.
Practice question 7 · Classes and objects
What does this code print?
class Counter:
hits = []
def add(self, x):
self.hits.append(x)
a = Counter()
b = Counter()
a.add(1)
b.add(2)
print(a.hits, len(Counter.hits))- A. [1, 2] 2
- B. [1] 0
- C. [1] 2
- D. It raises an AttributeError
Show answer
Answer: A. hits is a class variable, so there is one list shared by the class and all its instances. self.hits.append() changes that shared list instead of creating a new one, so both calls add to it. B and C assume each instance has its own list, which needs self.hits = [] in __init__. D is wrong because instances can read class attributes through self.
Practice question 8 · Files
What does this code print?
with open("log.txt", "w", encoding="utf-8") as f:
f.write("a\n")
with open("log.txt", "w", encoding="utf-8") as f:
f.write("b\n")
with open("log.txt", "a", encoding="utf-8") as f:
f.write("c\n")
with open("log.txt", encoding="utf-8") as f:
print(repr(f.read()))- A. ‘a\nb\nc\n’
- B. ‘c\n’
- C. ‘a\nc\n’
- D. ‘b\nc\n’
Show answer
Answer: D. Mode 'w' erases an existing file before writing, so the second block replaces a with b. Mode 'a' adds to the end, so c follows b. Each with block closes the file, so all writes are saved before the read. A treats 'w' as append. B treats 'a' as overwrite. C ignores the second 'w'.
Practice question 9 · Virtual environments
A team keeps its project in Git and each developer uses a virtual environment in a .venv folder. Which practice matches the official venv documentation?
- A. Commit the
.venvfolder so everyone gets the same installed packages - B. Keep
.venvout of Git and recreate it on each machine withpython -m venv, then reinstall the packages - C. Copy the
.venvfolder to the server, because it works from any path - D. Put the project’s source code inside the
.venvfolder so it is isolated
Show answer
Answer: B. The venv documentation says a virtual environment is not checked into source control, is disposable, and should be simple to delete and recreate. It suggests keeping a requirements file such as requirements.txt and reinstalling with pip install -r requirements.txt. A goes against that guidance. C is wrong because the documentation says environments are not movable or copyable. D is wrong because you do not place project code in the environment.
Practice question 10 · Unit testing
The unittest runner loads this class. How many tests does it run?
import unittest
class TestMath(unittest.TestCase):
def setUp(self):
self.x = 2
def test_add(self):
self.assertEqual(self.x + 2, 4)
def check_sub(self):
self.assertEqual(self.x - 2, 0)
def testMultiply(self):
self.assertEqual(self.x * 2, 4)- A. 1
- B. 3
- C. 2
- D. 4
Show answer
Answer: C. The runner treats only methods whose names start with test as tests, so it runs test_add and testMultiply. setUp() is not a test; it runs before each test. A misses that testMultiply also starts with test, even without an underscore. B wrongly counts check_sub. D counts every method, including setUp().
How did you score?
8–10 correct: take a full timed test to check your speed. Under 8: revise the topic you missed most, then try again. The Python programming practice tests have 450 more questions like these.
Common mistakes in Python practice tests
Common lost marks in a Python practice test come from a handful of habits: guessing the output instead of tracing it, and carrying rules over from another language.
- Using the result of
list.sort(). The Python sorting guide sayslist.sort()sorts in place and returnsNone;sorted()returns a new list. Both sorts are stable. - Forgetting shared references. Assigning a list to a second name, multiplying a list of lists, or using a mutable default or class variable all share one object.
- Comparing with
==when you meanis. PEP 8 says comparisons withNoneshould useisoris not. - Misreading indentation. An
elselined up withforbelongs to the loop, not to theifinside it. - Assuming other languages’ integer division. In Python, floor division rounds towards minus infinity and the remainder takes the sign of the right operand.
- Relying on the default file encoding. It changed in Python 3.15. The 3.15 release notes recommend always passing an explicit
encodingargument for compatibility between versions. - Studying Python 2 material. Python 2 was sunset on 1 January 2020. Old tutorials with
print "x"orraw_input()will mislead you.
If you already know the basics and want harder topics, our article on advanced Python practice tests on decorators, generators and concurrency is the next step. For web work, see the guides to Django practice tests on models, views and templates and Flask practice tests on routing, templates and APIs.
Python certification dumps vs practice tests
Practice tests that explain every answer are the safer and more useful choice: dumps for Python certifications are risky and often wrong. There is no official “Python programming” exam, so be careful with anything sold as real exam questions.
For the PCEP and PCAP certifications, dumps are question sets claimed to be copied from the live exam. Using or sharing live exam content breaks the exam rules candidates accept and can lead to a certificate being revoked.
Dump answers are also often wrong or out of date. Practice tests that explain why each option is right or wrong build the reasoning that code-reading questions test.
Python practice test and certification FAQs
How many questions are in the Exametics Python practice tests?
The Exametics Python Programming Practice Tests have 6 practice tests with 75 questions each, 450 questions in total, including a timed Exam Mode test. They are knowledge tests, not an official certification exam.
Are there free Python practice questions?
Yes. This post has 10 free Python practice questions with answers and explanations, covering numbers, lists, functions, control flow, dictionaries, exceptions, classes, files, virtual environments and unit testing. For a full Python practice test, the Exametics Python Programming Practice Tests have 450 more questions like these.
Which Python version should I practise with in 2026?
Use a supported Python 3 release. The Python Developer’s Guide lists Python 3.15 as the newest release line, first released on 9 October 2026, and Python 3.12 as receiving security fixes until October 2028 (scheduled). The code snippets in the Exametics questions were run with Python 3.12.
Is Python hard to learn, and how long should I prepare?
Python syntax is short and readable, but tests check details such as shared references, scope and exception order. If you already code a little, two to three weeks of focused practice with a Python practice test and the official tutorial is a realistic plan.
What is the passing score for a Python certification?
The Python Institute’s PCEP-30-03 exam has 35 questions in 50 minutes with a 70% passing score, and PCAP-31-04 has 42 questions in 65 minutes with a 72% passing score, according to the official PCEP and PCAP exam pages.
Which Python certification should I take first?
Start with PCEP, the Python Institute’s entry-level exam, which has no prerequisites. PCAP is the associate level; the official PCAP page lists no formal prerequisites but recommends PCEP-level knowledge.
Can I take the Python certification exams online?
The official PCEP and PCAP pages list delivery through TestNow, the OpenEDG Testing Service, and the Python Institute FAQ lists taking an exam online from home as an option. Check the exam page for current delivery options and prices before you buy a voucher, as the pages do not publish a fixed fee.
Official sources: The Python Tutorial and status of Python versions. Checked on 9 November 2026.
Test your Python with 450 practice questions
Six practice tests cover everyday Python 3, from syntax and data types to classes, files, virtual environments and unit testing. Every answer is explained, with a hint, so you learn from each mistake.
✓ Every answer explained · ✓ Timed exam mode · ✓ 30-day refund