Python interview questions

Want to become an expert in cracking Python interview questions?

Start with practicing the questions below. Whether a question involves multiple choice or live coding, we will give you hints as you go and tell you if your answers are correct or incorrect.

After that, take our timed public Python interview questions test.

To use our service for testing developers, purchase one of the paid plans for companies.


1. FileOwners
Python Language Public

Implement a group_by_owners function that:

  • Accepts a dictionary containing the file owner name for each file name.
  • Returns a dictionary containing a list of file names for each owner name, in any order.

For example, for dictionary {'Input.txt': 'Randy', 'Code.py': 'Stan', 'Output.txt': 'Randy'} the group_by_owners function should return {'Randy': ['Input.txt', 'Output.txt'], 'Stan': ['Code.py']}.

Easy  
10min
Solve question

2. Palindrome
Python Strings Public

A palindrome is a word that reads the same backward or forward.

Write a function that checks if a given word is a palindrome. Character case should be ignored.

For example, is_palindrome("Deleveled") should return True as character case should be ignored, resulting in "deleveled", which is a palindrome since it reads the same backward and forward.

Easy  
10min
Solve question

3. Path
Python Data structures Strings Public

Write a function that provides change directory (cd) function for an abstract file system.

Notes:

  • Root path is '/'.
  • Path separator is '/'.
  • Parent directory is addressable as '..'.
  • Directory names consist only of English alphabet letters (A-Z and a-z).

For example:

path = Path('/a/b/c/d')
print(path.cd('../x').current_path)

should display '/a/b/c/x'.

Note: Do not use built-in path-related functions.

Hard  
30min
Solve question

If you feel ready, take one of our timed public Python interview questions tests:

  • HTML/CSS, JavaScript, Python, and SQL online test (Easy / Hard)
  • Python online test (Easy)
  • Python and SQL online test (Easy / Hard)
Not exactly what you are looking for? Go to our For developers section.