Python Interview Questions Cheat Sheet
Basics
- Python is an interpreted, dynamically typed, high-level programming language.
- Common data types: int, float, str, bool, list, tuple, dict, set, NoneType.
- List vs Tuple: Lists are mutable, tuples are immutable.
- 'is' checks identity, '==' checks value.
- PEP 8: Style guide for Python code.
Intermediate
- *args allows variable-length positional arguments; **kwargs allows keyword arguments.
- List comprehension: [x*x for x in range(5)]
- Decorator: A function that wraps another to modify behavior.
- Shallow copy: one level deep; Deep copy: full recursive copy.
Advanced
- GIL: Global Interpreter Lock, prevents multi-threaded execution in CPython.
- Generator: Uses 'yield', returns an iterator.
- Coroutine: Generator that can consume values with send().
- MRO: Method Resolution Order for classes with multiple inheritance.
Coding Challenges
- Reverse a string: s[::-1]
- Palindrome: s == s[::-1]
- Duplicates: [i for i, c in Counter(lst).items() if c > 1]
- FizzBuzz: for i in range(1,101): print("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or i)
Libraries & Frameworks
Python Interview Questions Cheat Sheet
- Flask vs Django: Flask is lightweight; Django is full-featured.
- Pandas: Used for DataFrame-based data analysis.
- NumPy: Array computing and linear algebra.
- SQLAlchemy: ORM for SQL databases.