Python Programming Fundamentals
Core Python concepts every developer should know.
What is a list comprehension?
[expr for item in iterable if condition] โ a concise way to build lists. E.g. [x**2 for x in range(10) if x % 2 == 0]
What is the difference between a list and a tuple?
Lists are mutable (can be changed), tuples are immutable. Tuples use () and are faster; lists use [].
What does *args do in a function signature?
Collects extra positional arguments into a tuple, allowing a function to accept any number of positional args.
What does **kwargs do?
Collects extra keyword arguments into a dictionary, letting a function accept any number of named args.
What is a decorator?
A function that wraps another function to extend its behaviour without modifying it. Applied with @decorator_name.
Explain Python's GIL
The Global Interpreter Lock prevents multiple native threads from executing Python bytecode simultaneously, limiting CPU-bound parallelism in CPython.
What is a generator?
A function that yields values one at a time using 'yield', producing an iterator without storing all values in memory.
What is the difference between '==' and 'is'?
'==' checks value equality; 'is' checks identity (same object in memory). E.g. [1,2] == [1,2] โ True, but [1,2] is [1,2] โ False.
What are Python's built-in data types?
int, float, complex, str, bytes, list, tuple, range, dict, set, frozenset, bool, NoneType
What is a context manager?
An object implementing __enter__ and __exit__ used with 'with' statements to manage resources (e.g. files, locks) and guarantee cleanup.
How does Python handle memory management?
Via reference counting and a cyclic garbage collector. Objects are freed when their reference count drops to zero.
What is a lambda function?
An anonymous single-expression function: lambda args: expression. E.g. square = lambda x: x**2