Python is quick to start writing and surprisingly easy to misread. Code that runs without an error can still do something other than what its author meant, and someone who has only ever run their own scripts may never have had to say, in advance, what a line will do. The Python (Basic) test asks you to say it. It is meant for someone a few months into the language, after an introductory course, a first scripting or data project, or a run of practice problems, and it certifies that you can predict what ordinary Python does and write a small, correct function in it.
Most questions are short scripts followed by a handful of possible outputs. Others ask which error a line raises, which expressions are true, or which of several snippets is valid Python, and a few ask you to select every correct option, which scores only when the set is exact. After the multiple-choice questions comes an easy problem from the coding catalogue, solved in Python.
What you should be able to do
The questions cover nine topics in balance, so every sitting asks about each. The Python study plan teaches all of them in its early modules, from values and operators through to errors and exceptions.
- Types and operators. Say what
int,float,boolandstrvalues do in arithmetic and comparisons: true division and floor division, operator precedence, truthiness, and the difference between==andis. - Control flow. Trace
if/elifchains andforandwhileloops by hand, withbreak,continue,rangeandenumerate, and count exactly how many times a body runs. - Strings. Index and slice, use the common methods such as
split,join,strip,replaceandfind, format with f-strings, and remember that every string method returns a new string. - Lists and tuples. Tell the methods that change a list from the ones that return something new, slice and copy, build nested lists, and unpack tuples.
- Dictionaries and sets. Look up keys with and without a default, iterate in the right order, count with a dictionary, know what may be a key, and use the set operations.
- Functions. Positional, keyword and default arguments,
*args, return values, and what happens to a list that is passed into a function. - Comprehensions. List, dict and set comprehensions with filters and conditional expressions, and what a generator expression produces.
- Classes and objects.
__init__,self, methods, instance and class attributes, and__str__. - Exceptions.
try,except,elseandfinally, the common built-in exceptions and which operation raises which, and raising your own with a message.
Solving the coding problem in Python
The coding problem is one of the catalogue's easy problems, like those under Strings, Arrays, Hash Table and Counting. You get a function to complete, with type hints that say what comes in and what to return, for example def longestRun(nums: List[int]) -> int:. Function names follow the catalogue's camelCase even in Python, and List is imported for you when the signature uses it. The platform supplies the input and checks the value you return, so there is nothing to read or print.
Run tries your function on the visible examples. Submit runs it on thousands of hidden, generated inputs and gives credit for each one it passes, so think about the inputs the examples do not show: a list of one element, repeated values, negative numbers, a string with nothing to find. Pasting is switched off, which means the idioms you rely on, such as enumerate, zip, sorted with a key, dict.get and collections.Counter, need to be ones you can type correctly from memory.
Most easy problems turn on one idea used carefully. The roadmap lessons on strings, arrays and hashing explain the common ones with Python code beside the other languages.
A study route
- Start with the modules of the Python study plan for any topic above that you are unsure of. Each lesson has a short quiz and exercises that the judge checks, and the quizzes ask the same kind of question the test does.
- Use the interpreter as a checker, not a crutch. Type a line you are unsure of, such as
print(round(2.5), round(3.5)), decide what it will print, then press Enter. When your prediction is wrong, find out why before moving on. - Solve easy catalogue problems in Python with a timer running, and submit before you read the editorial. Then read the editorial anyway: it often shows a shorter way to write the same idea.
- Read code you did not write. The bug hunts in Python ask you to find the line that makes a working-looking program wrong, which is the reading skill the multiple-choice questions reward.
Where learners usually go wrong
- Not knowing whether a method changes its object. For every method you use, know whether it modifies the object or returns a new value. Lists are changed in place by many of their methods; strings never are.
- Thinking of a variable as a box. A Python variable is a name attached to an object. Two names can be attached to the same list, and attaching a name to a new object never changes the old one. Draw the names and arrows when a question passes objects around.
- Guessing the error type. Learn the difference between
TypeError(the wrong kind of value),ValueError(the right kind with a bad value),IndexError,KeyErrorandNameError. Questions often offer them side by side. - Skimming slices and ranges. A slice includes its start and excludes its stop, a negative index counts from the end, and a step can run backwards. Work them out position by position rather than by eye.
When to aim for Intermediate
Python (Intermediate) moves from what everyday code does to the rules underneath it: scope and closures, iterators and generators, decorators and context managers, the object model with inheritance and special methods, and the standard library modules a working programmer reaches for. Its coding round goes up to medium difficulty. If you write Python at work or in sizeable projects, it is the better fit; if most of your Python so far is coursework and practice problems, start here.