Buy to unlock all questions, full reading mode and PDFs.
About this question bank
Questions
139 in total
Free to try
20 questions (no sign-up)
Exam domains
5 domains
Price
JPY 1,500 (≈ US$10; shown in your local currency at checkout) · one-time payment · 3 months
PDF
Japanese–English · Chinese–English · Korean–English · English (for buyers)
Data version
2026-12
About this exam
An associate-level certification from the Python Institute for Python programmers. Going a step beyond PCEP, it covers modules and packages, strings, exception handling, and object-oriented programming (classes, inheritance, instance and class variables).
Try a sample question
This is an original sample question written by itmoshi based on the exam objectives.
Shared helpers live in a module, tools.py, which main.py uses (see the exhibit). When you run python main.py in the same directory, which lines are printed, in order (/ marks a line break)?
Exhibit
# tools.py
print("loading tools")
def helper():
return "help"
if __name__ == "__main__":
print("tools run directly")
# main.py
import tools
import tools
from tools import helper
print(__name__, tools.__name__, helper())
Aloading tools / loading tools / __main__ tools help
Bloading tools / tools run directly / __main__ tools help
Cloading tools / tools __main__ help
Dloading tools / __main__ tools help
Show answer and explanation
Answer:D It prints two lines: loading tools / __main__ tools help.
Why it is correct
On the first import, Python creates the module, puts it in sys.modules, and then executes its top-level code. The second import tools and the from tools import helper just reuse that module, so loading tools is printed once. An imported module's __name__ is its module name, "tools", so the if __name__ == "__main__": block does not run. main.py, run directly, has __name__ set to "__main__", so the last line is __main__ tools help.
The other options
✗ A This assumes each import re-executes the module. Later imports simply return the module already in sys.modules; use importlib.reload if you really need to run it again.
✗ B This assumes the __main__ block runs in an imported module. It runs only when tools.py itself is executed directly, as in python tools.py.
✗ C This swaps the two __name__ values. The script run directly is "__main__"; an imported module gets its module name.
Key takeaway
import → runs only the first time (later imports reuse sys.modules; re-run with importlib.reload). __name__ → "__main__" when run directly, the module name when imported.