InterviewStack.io LogoInterviewStack.io

Python Fundamentals and Core Syntax Questions

Comprehensive knowledge of core Python language features and syntax, including primitive and composite data types such as integer numbers, floating point numbers, strings, booleans, lists, dictionaries, sets, and tuples. Candidates should understand variable assignment and naming, operators for arithmetic, logical, and comparison operations, and control flow constructs including conditional statements and loops. Expect familiarity with function definition, invocation, parameter passing, return values, and scope rules, as well as common built in functions and idioms such as iteration utilities, list comprehensions, generator expressions, and basic functional utilities like map and filter. Candidates should demonstrate error and exception handling techniques and best practices for writing readable and maintainable code with modularization and clear naming. Practical skills include file input and output, working with common data formats such as comma separated values and JavaScript Object Notation, selecting appropriate data structures with attention to performance and memory characteristics, and applying memory efficient patterns for processing large data sets using iterators and generators. Familiarity with the standard library and common utilities for parsing and transforming data, and the ability to write small code snippets to solve algorithmic and data manipulation tasks, are expected.

HardTechnical
62 practiced
You have expensive CPU-bound preprocessing functions that need to be parallelized in Python. Compare the trade-offs between using multithreading, multiprocessing, and asynchronous I/O for this workload. Then provide a sample implementation using concurrent.futures.ProcessPoolExecutor that parallelizes a CPU-bound function over chunks while minimizing memory copying (for example via memory-mapped files or numpy memmap).
EasyTechnical
72 practiced
Describe the core built-in Python data types: int, float, bool, str, list, tuple, set, and dict. For each type give a concise example (in Python), state whether it is mutable or immutable, typical machine-learning pipeline use cases (for example feature vectors, configuration maps, unique id sets), and performance implications for membership testing, iteration, and memory footprint. Mention any gotchas an ML engineer should be aware of when choosing between these types.
MediumTechnical
64 practiced
Design and implement a Python 3 DatasetIterator class that accepts any iterable data source and yields minibatches of size batch_size. The iterator should support an optional shuffle flag and a reproducible random seed and handle the last incomplete batch by yielding it or dropping it based on a parameter. Describe how this iterator could integrate with a training loop.
HardTechnical
70 practiced
Create a Python 3 decorator 'timed_lru_cache' that both times function execution and caches results. The decorator should handle unhashable arguments by serializing them deterministically (for example via json.dumps with sort_keys) before using as cache keys. Discuss the limitations and security considerations of using serialization for cache keys and show example usage.
MediumTechnical
81 practiced
A Python-based model serving process leaks memory gradually in production. Describe the debugging steps you would take to find and fix the leak using standard Python tools (tracemalloc, gc, objgraph, logging). Include a prioritized list of quick mitigations you might apply to reduce the business impact while you find a permanent fix.

Unlock Full Question Bank

Get access to hundreds of Python Fundamentals and Core Syntax interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.