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 tooTruthiness
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 basketLists, 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) # TrueCommon 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.
Basic
Functions & control flow
- Loops
- Function arguments
- Scope
Quiz for this level coming soon.
Intermediate
Data structures
- Lists and tuples
- Dictionaries and sets
- Comprehensions
Python quizzes
- PythonBeginner
Python Basics
Types, operators and strings
OperatorsVariablesStrings7 Qs~5mStart - PythonIntermediate
Lists, Tuples, Sets & Dicts
Choosing and using built-in collections
SetsListsDictionaries7 Qs~5mStart - PythonIntermediate
Python Functions
Arguments, scope and closures
Default argumentsArgumentsScope7 Qs~5mStart - PythonAdvanced
Advanced Python
Generators, decorators and class attributes
GeneratorsDecoratorsFile handling7 Qs~5mStart - PythonExpert
Python Interview Questions
Concurrency, copying, dataclasses and idioms
ConcurrencyIdentityMethods7 Qs~5mStart
Interactive Python challenges
Hands-on activities: find bugs, complete code, order steps and match concepts.
Python articles
Python Viva Questions and Answers for Students
A rapid-fire set of Python viva and oral exam questions with short, precise answers, grouped by topic so you can revise quickly before a practical exam.
Python Quiz Preparation: A Practical Guide to Python MCQs
How Python multiple-choice questions are usually built, the traps that catch most learners, and a study routine that uses practice and exam-mode quizzes effectively.
Python Functions Explained: Arguments, Scope and Common Traps
A practical tour of how Python functions receive arguments, resolve variable names and hold on to state, with the mistakes that catch most learners.
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.