Courseiva
Question 429 of 498
Control Flow, Loops, Lists and LogichardMultiple ChoiceObjective-mapped

PCEP Control Flow, Loops, Lists and Logic Practice Question

Exhibit

Refer to the exhibit.

# config.py
allowed_ports = [80, 443, 8080]

def check_port(port):
    if port in allowed_ports:
        return True
    else:
        return False

# main.py
from config import check_port
print(check_port(80))

A developer runs main.py and gets True. They then modify config.py by adding `allowed_ports.append(22)` and run main.py again without restarting the interpreter. What is the output?

⚠ Common exam trap

Test-takers frequently assume Python re-executes the imported module each time it is imported, but in reality, Python caches modules and only loads them once per interpreter session, so modifications to the source file after the first import are ignored.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

True

Python imports modules only once per interpreter session; subsequent imports use the cached module object. Since `config.py` was already imported, modifying the file does not affect the already-loaded list object in memory. The `allowed_ports` list remains unchanged, so the condition that originally returned `True` still holds.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • False

    Why it's wrong here

    Port 80 is still in the list.

  • None

    Why it's wrong here

    Function returns a boolean.

  • Error

    Why it's wrong here

    No error.

  • True

    Why this is correct

    The module is not reloaded, so the function still uses the original list.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 11, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.