Python Practice Online

Python looks simple, which is why interviewers probe the details: mutability, scoping, iteration and performance. Use these questions to find gaps, then write code in the browser editor on Quick Tech Learners.

Python concepts interviewers ask about

What is the mutable default argument pitfall?

Default values are evaluated once, when the function is defined. A default list or dict is therefore shared between calls. Use None as the default and create the object inside the function.

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

What is the difference between == and is?

== compares values using __eq__. is checks object identity. Use is for singletons such as None; do not use it to compare numbers or strings.

List comprehension vs generator expression?

A list comprehension builds the whole list in memory. A generator expression produces items lazily, which uses far less memory when you only iterate once, for example sum(x * x for x in numbers).

What does the GIL mean for threads?

In the standard CPython build, the Global Interpreter Lock lets only one thread execute Python bytecode at a time. Threads still help with I/O-bound work; for CPU-bound work use multiprocessing or native extensions. Recent CPython versions include an optional free-threaded build.

What is a decorator?

A decorator is a callable that takes a function and returns a wrapped version, applied with @name syntax. Use functools.wraps so the wrapper keeps the original name and docstring.

Practice exercises with approaches

Two Sum: return indices of two numbers that add up to a target.

Keep a dict of value to index while scanning, and check whether target minus the current value was already seen. O(n) time.

def two_sum(nums, target):
    seen = {}
    for i, n in enumerate(nums):
        if target - n in seen:
            return [seen[target - n], i]
        seen[n] = i
    return []

Count word frequencies in a text.

Split the text, normalise case and punctuation, and count with collections.Counter. Counter.most_common(n) gives the top n words.

Check whether brackets in a string are balanced.

Use a stack: push opening brackets, and on a closing bracket pop and check that it matches. The string is balanced if the stack is empty at the end.

Practice this on Quick Tech Learners

Reading answers is only the first step. Quick Tech Learners lets you turn Python exercises into active practice once you create an account and sign in.

  • Interview Insights: browse interview questions shared by the community and filter them by topic tag.
  • Practice Quiz: choose the concepts you want to revise, answer questions, and review how you did.
  • Coding Practice: write and run code in a browser editor against test cases. Pick a language, a difficulty band from Beginner to Expert, and either Practice mode (with hints) or Interview mode.
  • Study Plan and reports: set the topics you are preparing, then check performance, mastery and readiness reports to see where the gaps are.
  • Share Interview Question: add a question you were asked so other learners can practise it.