5 Quizzes•35 Questions

Learn Python

Python is used for scripting, web backends, automation and data science. These quizzes move from syntax and data types to functions, collections and the language features interviewers like to probe.

Written against Python 3.10+.

What you will practise

  • Reading and predicting Python code
  • Writing functions with sensible defaults
  • Choosing between lists, tuples, sets and dicts
  • Generators, decorators and context managers

Python lesson

A short introduction to the ideas behind the quizzes, before you start practising.

Python reads close to plain English, which makes it a common first language, but that readability hides a few behaviours that catch beginners off guard: how variables really work, what counts as true or false, and how default values behave.

Key concepts

Variables are labels, not boxes

A Python variable is a name bound to an object. Assigning `y = x` does not copy the value; both names point at the same object. For mutable objects like lists, changing one name’s contents changes what the other name sees too.

x = [1, 2, 3]
y = x
y.append(4)
print(x)  # [1, 2, 3, 4] — x changed too

Truthiness

Every value has a boolean meaning, not only True and False. Empty collections, empty strings and 0 are falsy; almost everything else is truthy. This lets you write `if items:` instead of `if len(items) > 0:`.

for value in [0, "", [], None, "hi", [1]]:
    print(value, "->", bool(value))

Functions and default arguments

A function is defined with `def`, and parameters can have default values. The dangerous part: a mutable default (like a list) is created once, when the function is defined, and shared across every call that does not override it.

def add_item(item, basket=None):
    if basket is None:
        basket = []
    basket.append(item)
    return basket

Lists, tuples, sets and dictionaries

Lists are ordered and mutable, tuples are ordered and immutable, sets hold unique unordered items with fast membership checks, and dictionaries map keys to values. Picking the right one is usually about whether you need order, uniqueness or fast lookup.

ages = {"Asha": 21, "Ravi": 23}
print(ages["Asha"])       # 21
print("Asha" in ages)     # True

Common mistakes

  • Using a mutable default argument (`def f(x, cache=[])`) and being surprised it keeps old values between calls.
  • Comparing floats with `==` after arithmetic (0.1 + 0.2 == 0.3 is False because of floating-point rounding).
  • Forgetting that slicing and most list methods return a new list, but `.sort()` and `.append()` mutate in place and return `None`.
  • Mixing tabs and spaces for indentation, which Python treats as a syntax error rather than silently accepting.

Quick recap

  • Variables bind names to objects; mutable objects can be changed through any name that refers to them.
  • Falsy values include 0, empty strings, empty collections and None.
  • Avoid mutable default arguments; use None and create the object inside the function.
  • Choose lists for order, tuples for fixed unchanging data, sets for uniqueness and fast lookup, dicts for key-based access.

Ready to test this? Take the Python Basics quiz →

Roadmap

Work through the levels in order, or jump to where you are.

1

Beginner

Foundations

  • Variables and types
  • Operators
  • Strings
  • Conditionals

Python Basics

2

Basic

Functions & control flow

  • Loops
  • Function arguments
  • Scope

Quiz for this level coming soon.

3

Intermediate

Data structures

  • Lists and tuples
  • Dictionaries and sets
  • Comprehensions

Lists, Tuples, Sets & Dicts, Python Functions

4

Advanced

Language internals

  • Generators
  • Decorators
  • Mutable defaults
  • Context managers

Advanced Python

5

Expert

Interview depth

  • Complexity trade-offs
  • Concurrency basics
  • Testing

Python Interview Questions

Python quizzes

Interactive Python challenges

Hands-on activities: find bugs, complete code, order steps and match concepts.

All Python challenges →

Python articles

FAQ

Which Python version do the quizzes assume?

Python 3.10 or newer. Where behaviour differs between versions, the explanation says so.

I am new to programming. Where should I start?

Start with Python Basics, then move to Functions and Collections.

Are these quizzes good for Data Science interviews?

Yes. Understanding how lists, tuples, and dictionaries work under the hood is critical for data science roles. The advanced quizzes cover list comprehensions and generator expressions.

Is Python pass-by-value or pass-by-reference?

Python uses "pass-by-object-reference". Our advanced quizzes have specific questions explaining what happens when you mutate a list inside a function vs reassigning it.

Do you cover popular libraries like Pandas or NumPy?

Currently, these quizzes focus strictly on the Python standard library and language fundamentals. Library-specific quizzes are planned for the AI & Data category.