HomebaseWorks

Python practical and code-reading questions

Short code snippets interviewers show on screen, with what to say about each.

EWritten by the HomebaseWorks editorial team · reviewed 26 Oct 2026
1
What does 7 // 2, 7 % 2, 7 / 2 give?

3, 1 and 3.5. Floor division, remainder, true division.

2
What is wrong with 'except:' on its own?

It catches everything, including KeyboardInterrupt and real bugs, and makes failures silent. Catch the specific exception, or at least Exception, and log it.

3
How do you read a file line by line?

with open(path) as f: for line in f: ... The with statement closes the file; iterating the file object reads lazily, so large files are fine.

Advertisement
4
What does sorted() return versus list.sort()?

sorted returns a new list and works on any iterable; list.sort() sorts in place and returns None. Returning the result of .sort() is a classic bug.

5
What is a virtual environment and why use one?

A per-project Python install with its own packages. It stops version conflicts between projects and makes requirements reproducible.

6
Write a function that returns the most common word in a string.

Split on whitespace, count with collections.Counter, return counter.most_common(1)[0][0]. Mention lowercasing and stripping punctuation if the interviewer asks about edge cases.

Practise out loud. Say each answer once as written, then again in your own words with your own number or story.

Have a number ready. "My Python score is at benchmark on a timed test" is a stronger answer than "I am good at it". Take the test and quote the result.

Advertisement
Continue with Python4 lessons · 2 interview sets · 1 test · 1 certificate
Not tested

More in Programming