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.

MediumTechnical
84 practiced
As a data scientist, you inherit a Python script with long functions, poor variable names, and no tests. Describe a step-by-step plan to refactor the codebase to improve readability, modularity, and testability while minimizing risk to production. Include concrete tactics and short-term vs long-term actions.
HardTechnical
71 practiced
Implement the Misra-Gries algorithm (a deterministic k-heavy hitters algorithm) in Python to find items that may appear more than n/k times in a stream. The function should accept an iterable and k and return candidate items and their estimated counts. Discuss algorithm accuracy and memory guarantees.
HardTechnical
70 practiced
Given a large gzip-compressed newline-delimited JSON file (ndjson), design a Python pipeline that streams and parses the file, aggregates counts by a specified key, and writes partial aggregates periodically to disk to limit memory usage and allow checkpointing. Provide code outline using gzip and json modules and describe failure recovery.
HardTechnical
122 practiced
Implement a Python iterator class Peekable that wraps any iterator and supports peek() to view the next element without consuming it, and pushback(value) to place a value back into the stream so subsequent next() returns it. Ensure correct behavior for multiple pushes and for an exhausted underlying iterator.
HardTechnical
61 practiced
Implement a robust CSV reader in Python that handles varying column counts per row, different delimiters, quoted fields, and malformed lines. The reader should yield a dict per row keyed by header names when a header exists and report parsing errors with line numbers without crashing the whole pipeline.

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.