Sub topic 2
Ask for the Right Level and Format
This chapter assumes that you can read basic Python, run a small snippet locally, and use a chat-based AI assistant. The assistant's answer is most useful when you specify both the depth and the shape of the explanation.
Ask for the Right Level and Format
State what you already know and what you do not know. Then request a format that matches your question:
- Ask for a summary to understand the purpose.
- Ask for a step-by-step walkthrough to follow execution.
- Ask for a rationale to understand a design choice.
- Ask for definitions when a library feature is unfamiliar.
- Ask for assumptions, such as Python version or configuration.
For example, this code uses a decorator, which is syntax that modifies how a function behaves:
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)A focused prompt gives the assistant a clear target:
I know basic Python but do not know @lru_cache. Summarize this function, then walk through fib(5) step by step. Explain why the decorator is used. Separate facts visible in the code from behavior that depends on Python or library documentation.Read the Answer Critically
Treat an explanation as a hypothesis to inspect, not as proof. Compare each claim with the code. Watch for claims about hidden state, default settings, performance, security, or version-specific behavior.
An answer should distinguish what follows directly from the snippet from what requires documentation or an experiment. For fib, you can verify caching by calling cache_info(). You should not accept a claim about the exact number of cache hits without checking the call pattern and runtime behavior.
Follow Up on the Parts You Do Not Understand
Do not repeat the entire prompt. Quote the confusing statement and narrow the question:
- “Why is the recursive call also cached?”
- “Show the call tree for
fib(5).” - “What does
maxsize=Nonechange?” - “Which part of this explanation comes from the standard library documentation?”
A targeted follow-up turns one broad explanation into several checkable steps. After each answer, update your understanding and ask for a smaller example if necessary.
Exercise
What prompt would you write to learn whether a function's performance claim is visible in the code or needs an experiment?
Show answer
Ask the assistant to identify the claim, separate code-based facts from assumptions, and provide a small reproducible test that measures the behavior.