Explain Code Line by Line
Get a plain-English walkthrough of unfamiliar code, pitched at your experience level, with the key concepts called out.
Make it yours
Fill in each variable and watch the prompt update. Anything still in {{braces}} needs your input before you use it.
Fill in the blanks
0 of 3 filledProgramming language.
Your background, so the explanation fits.
The code snippet to explain.
You are a patient programming tutor. Explain the {{language}} code below to someone at this level: {{experience_level}}. Format: 1. **Big picture** — one or two sentences on what the code does overall. 2. **Line by line** — walk through it in order. Group trivial lines together; spend more time on anything tricky. 3. **Key concepts** — list up to 3 concepts used here that are worth learning, with a one-sentence definition each. 4. **Watch out** — mention any bugs, edge cases, or risky patterns you notice. If there are none, say so. Don't rewrite the code unless I ask. If something depends on context you can't see (like an imported function), say what you're assuming. Code: """ {{code}} """
Example
Example input
You are a patient programming tutor.
Explain the Python code below to someone at this level: a beginner who knows variables and loops but not dictionaries.
Format:
1. **Big picture** — one or two sentences on what the code does overall.
2. **Line by line** — walk through it in order. Group trivial lines together; spend more time on anything tricky.
3. **Key concepts** — list up to 3 concepts used here that are worth learning, with a one-sentence definition each.
4. **Watch out** — mention any bugs, edge cases, or risky patterns you notice. If there are none, say so.
Don't rewrite the code unless I ask. If something depends on context you can't see (like an imported function), say what you're assuming.
Code:
"""
def word_counts(text):
counts = {}
for word in text.lower().split():
counts[word] = counts.get(word, 0) + 1
return sorted(counts.items(), key=lambda pair: pair[1], reverse=True)
"""Example output
Big picture: This function counts how many times each word appears in a piece of text and returns the words sorted from most to least common.
Line by line:
def word_counts(text):— defines a function that takes one input,text.counts = {}— creates an empty dictionary: a collection that maps keys (here, words) to values (here, counts).for word in text.lower().split():— lowercases the text so "The" and "the" match, then splits it on whitespace into a list of words, and loops over them.counts[word] = counts.get(word, 0) + 1— looks up the word's current count (or 0 if it's new) and adds 1.return sorted(...)— turns the dictionary into a list of(word, count)pairs and sorts by the count (pair[1]), highest first.
Key concepts:
- Dictionary — stores key/value pairs for fast lookup.
.get(key, default)— reads a value without crashing if the key is missing.lambda— a tiny unnamed function, used here to tellsortedwhat to sort by.
Watch out: Punctuation stays attached to words, so "end." and "end" are counted separately.
Why it works
Stating the experience level is the most important part: the same code needs a very different explanation for a beginner than for a senior developer.
The fixed four-part format keeps answers consistent and skimmable, and the "Watch out" section turns a passive explanation into a mini code review. Asking the model to state its assumptions about code it can't see reduces confident-but-wrong guesses.
Techniques used
- Role promptingAsk the AI to respond as a specific role or expert to shape its focus, vocabulary, and tone for your audience.Learn the technique
- Structured output promptingAsk for answers in a precise format — tables, JSON, CSV, or fixed sections — so results are easy to scan, compare, or reuse.Learn the technique