← Back to all blog posts
Jump to article
Programming article

Python Interview Questions and Answers for Beginners

The Python basics interviewers test - data types, loops, functions, and gotchas.

Python Interview Questions and Answers for Beginners

These Python questions come up for junior developer, data and automation roles. Read the answer, then write the code yourself - the free Learn Python course runs every example in your browser.

Data types

List vs tuple? A list is mutable (you can change it); a tuple is immutable. Use a tuple for fixed collections and as dictionary keys. See dictionaries.

What is a dictionary? An unordered-by-design mapping of keys to values, with fast lookup by key.

Mutable vs immutable? Lists, dicts and sets are mutable; strings, numbers and tuples are immutable - reassigning them makes a new object.

Control flow and functions

What does a function return by default? None, if there is no return.

*args and **kwargs? They let a function take any number of positional and keyword arguments.

What is a list comprehension? A concise way to build a list: [x*2 for x in nums if x > 0].

Common gotchas

Why not use a mutable default argument? def f(x, items=[]) reuses the same list across calls - use None and create it inside.

== vs is? == compares values; is compares identity (the same object in memory).

How does Python handle integers and division? / gives a float; // is floor division.

Practise writing it

You remember what you type. Work through the free Learn Python course - every lesson runs real Python in the browser with exercises.

HOME LABS COMMUNITY DASHBOARD