Python Interview Questions - Interview Prep
50 Questions Available
Comprehensive collection of 50 essential Python interview questions covering data structures, OOP, decorators, generators, and advanced Python concepts. Free Python interview questions with answers. Python interview prep guide.
All Questions & Answers
What is Python and what are its main features?
Python is a high-level, interpreted programming language. Main features include dynamic typing, automatic memory management, extensive standard library, multiple programming paradigms (OOP, functional, procedural), simple syntax, and cross-platform compatibility.
What is the difference between list and tuple?
Lists are mutable (can be modified), use square brackets [], slower for large data. Tuples are immutable (cannot be modified), use parentheses (), faster, can be used as dictionary keys. Use lists for dynamic data, tuples for fixed data.
What is a dictionary in Python?
Dictionary is unordered collection of key-value pairs. Keys must be immutable (strings, numbers, tuples). Access values by key. Fast lookups O(1). Created with {} or dict(). Methods: get(), keys(), values(), items().
What is list comprehension?
List comprehension is concise way to create lists. Syntax: [expression for item in iterable if condition]. More readable and faster than loops. Can be nested. Alternative to map() and filter().
What is the difference between == and is?
== compares values (equality). is compares object identity (same object in memory). Use == for value comparison, is for checking if variables point to same object. Small integers and strings may be interned.
What are Python decorators?
Decorators are functions that modify other functions. Use @decorator syntax. Wraps function, adds functionality before/after execution. Used for logging, timing, authentication, caching. Can accept arguments.
What is a generator in Python?
Generator is function that yields values instead of returning. Uses yield keyword. Lazy evaluation - produces values on demand. Memory efficient for large sequences. Returns generator object. Can be iterated once.
What is the difference between append() and extend()?
append() adds single element to end of list. extend() adds all elements from iterable to list. append() increases length by 1, extend() increases by length of iterable.
What is *args and **kwargs?
*args collects positional arguments into tuple. **kwargs collects keyword arguments into dictionary. Allows functions to accept variable number of arguments. *args before **kwargs. Useful for wrapper functions.
What is lambda function?
Lambda is anonymous function defined with lambda keyword. Syntax: lambda arguments: expression. Single expression only. Used for short functions, map(), filter(), sorted(). More concise than def.