← Back to videos

Junior Python interview: how print() can stump you

Interview timeline Click any block to jump

Interview breakdown

Interviewer verdict
Passed with caveats Level: Entry-level Junior (conditional on solidifying core fundamentals)

Conditional pass for an entry-level Junior role: the candidate reasoned actively and recovered well on parts of the code-reading task, but made numerous basic theoretical mistakes around print() defaults, standard I/O streams, string literal concatenation, and output buffering.

Candidate: Dmitry
Target role: Junior Python Developer

29 y/o · economics degree, no prior commercial dev experience, taking Python courses and solving practice problems · first interview

Answers accuracy 12 total
42% score
Theory
2/8 correct · 44%
Live coding
1/4 correct · 38%
Practical task
Partially solved

Tricky print() loop: dynamic sep/file indexing, implicit string concatenation, and flush buffering

Initially misread [...][t % 4] as two adjacent lists before realizing it indexes into the list via modulo. However, he predicted a SyntaxError on implicit string literal concatenation (" " " "), did not recognize sys.stderr, and could not explain why omitting newlines (end=", ") buffers all output until loop completion unless flush=True is passed.

Topics covered Click a topic to filter questions

Candidate strengths

  • + Composed dialogue and active think-aloud reasoning during his first stress-test interview
  • + Knowledge of the context manager dunder protocol (__enter__ and __exit__) and resource cleanup
  • + Ability to revise an initial misreading in code (spotting list indexing via modulo %)
  • + Practical awareness of print()'s end and file keyword parameters

Areas to improve

  • → Review official docs for built-in fundamentals (print() defaults like sep=' ', str() conversion of arguments)
  • → Understand OS standard streams (stdin, stdout, stderr), terminal emulators, and command-line shells
  • → Learn how output stream buffering works and why flush=True forces immediate output
  • → Practice explaining technical concepts and reasoning shifts clearly in plain language

Questions in this interview

12 / 12
01 ▶ 04:12
How does built-in print() work, and how many positional arguments can it accept?
Theory Functions, scopes & closures
?
Candidate's answer

Stated that print() accepts an arbitrary number of arguments of any type, bounded in practice only by available memory.

Key takeaway

print(*objects, sep=' ', end='\n', file=None, flush=False) packs arbitrary positional arguments via *objects, limited only by memory.

Open moment on YouTube ↗
#01
02 ▶ 06:20
Does print() convert objects before outputting them, and does printing 1 look different from printing '1'?
Theory Strings, encodings & formatting
?
Candidate's answer

Initially guessed string conversion, then backtracked to claim no conversion happens and briefly suggested strings print with quotes before admitting confusion.

Key takeaway

print() converts every positional argument via str(obj) (__str__) before writing text to the stream, so print(1) and print('1') produce identical output without quotes.

Open moment on YouTube ↗
#02
03 ▶ 10:04
What is print()'s default separator between multiple arguments, and what types are valid for sep?
Theory Strings, encodings & formatting
?
Candidate's answer

Mistakenly said default sep is a comma with a space, though he correctly noted sep accepts any string (including '') and raises an error on an int.

Key takeaway

The default separator is a single space ' ' (also used when sep=None); passing anything other than str or None raises TypeError.

Open moment on YouTube ↗
#03
04 ▶ 13:05
Why do consecutive print() calls appear on new lines, and how do you suppress the trailing newline?
Theory Strings, encodings & formatting
?
Candidate's answer

Accurately identified the default end='\n' parameter and explained passing end='' to suppress the newline.

Key takeaway

end defaults to '\n' and is written after all arguments; setting end='' keeps subsequent output on the same line.

Open moment on YouTube ↗
#04
05 ▶ 14:08
Where does print() actually send data, and how do a terminal, a command-line shell, and standard I/O streams relate?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Mentioned the sys module and standard I/O streams, but confused the OS concepts — claiming a terminal cannot be used without Python and that sys creates streams.

Key takeaway

Every OS process inherits standard file descriptors stdin (0), stdout (1), and stderr (2); print() writes to sys.stdout by default, which a terminal emulator renders on screen.

Open moment on YouTube ↗
#05
06 ▶ 26:33
Can print() write directly to a file, and what object must be passed to its file parameter?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Correctly recalled that print() can write to a file opened via a context manager, but hedged between passing a filename string vs an open file object.

Key takeaway

print(..., file=f) requires a file-like object implementing .write(str), not a file path string.

Open moment on YouTube ↗
#06
07 ▶ 29:47
What is a context manager, why use it for files, and can it still close a file if power is suddenly cut?
Theory Decorators, iterators, generators & context managers
?
Candidate's answer

Correctly named __enter__ and __exit__ and explained cleanup when an exception occurs mid-block, but mistakenly suggested __exit__ might even handle a power outage.

Key takeaway

A with block guarantees __exit__ runs on normal exit or Python exceptions (like try/finally), but cannot run if the OS process is killed via SIGKILL or loses power.

Open moment on YouTube ↗
#07
08 ▶ 34:13
Does text passed to print() always appear on screen immediately as soon as print() runs?
Theory Modules, packages, imports & stdlib
?
Candidate's answer

Briefly confused the question with escape characters, then concluded that once execution reaches print(), output always appears immediately.

Key takeaway

sys.stdout is buffered (line-buffered on TTYs, block-buffered on pipes/files), so output without '\n' or flush=True stays in memory until the buffer flushes.

Open moment on YouTube ↗
#08
09 ▶ 36:25
What does [" " * 2, " ", " " " ", "\t"][t % 4] do when passed as sep to print()?
Live coding Control flow, loops & syntactic sugar
?
Candidate's answer

Initially misread adjacent brackets as two separate lists, then realized on his own that [t % 4] computes an index 0..3 to pick one separator string from the list.

Key takeaway

Subscripting can be applied directly to a list literal [...][idx], with t % n mapping any non-negative integer into valid indices 0..n-1.

Open moment on YouTube ↗
#09
10 ▶ 47:41
Is " " " " (two adjacent string literals with no + operator) valid Python syntax?
Live coding Strings, encodings & formatting
?
Candidate's answer

Predicted a SyntaxError if that index were selected, and could not explain why Python accepted two adjacent quoted literals after seeing it run.

Key takeaway

Adjacent string literals ('ab' 'cd') are implicitly concatenated at compile time by the Python parser into a single string.

Open moment on YouTube ↗
#10
11 ▶ 48:34
What do sys.stdout and sys.stderr represent in file=[sys.stdout, sys.stderr][t % 2]?
Live coding Modules, packages, imports & stdlib
?
Candidate's answer

First called them uninvoked functions, then correctly reasoned sys.stdout writes to the terminal, while admitting he had no idea what sys.stderr does.

Key takeaway

sys.stdout and sys.stderr are pre-opened file-like TextIOWrapper streams for standard output and diagnostics; both render in the terminal unless redirected separately.

Open moment on YouTube ↗
#11
12 ▶ 55:51
Why did print(..., end=', ') followed by time.sleep() display all items at once at the end instead of one by one, and how did flush=True change it?
Live coding Modules, packages, imports & stdlib
?
Candidate's answer

Expected item-by-item output on each sleep, blamed the file parameter when everything appeared at once, and did not know the flush=True parameter or stream buffering.

Key takeaway

Because end=', ' omitted '\n', line-buffered stdout held output in memory until program exit; flush=True forces an immediate stream flush on each call.

Open moment on YouTube ↗
#12
Original video description & timecodes

A mock interview for a Junior Python Developer, in which the ‘simple’ print() function suddenly turned into a full-blown stress test. We’ll break down the basics of Python, the sep, end, file and flush parameters, working with output, context managers, and how to think through your answers during an interview.

An excellent episode for those preparing for their first interview and wanting to understand why it’s important to know the basics of the language more deeply than it seems.

Timestamps:

00:00 — Start
00:48 — Introduction and interview format
04:12 — Starting with the “simple” print() function
10:04 — sep, end and separators in print()
14:08 — Terminal, command line and output stream
26:33 — Can you write to a file using print()
29:47 — Context manager in simple terms
34:13 — Does print() always output immediately?
36:15 — A practical exercise with code
57:42 — The flush parameter and why everything “froze”
1:01:00 — The candidate’s self-assessment after the interview
1:03:37 — Feedback