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
66 practiced
You must compute the top-k most frequent tokens from a text corpus that is too large to fit into memory (single machine). Describe and implement a memory-efficient Python approach (use standard library) that streams the file and returns top-k token-frequency pairs. Discuss trade-offs and how to handle very large vocabularies.
HardTechnical
58 practiced
Create a small utility in Python that safely evaluates a simple arithmetic expression received as a string (numbers, +, -, *, /, parentheses) without using eval(). The evaluator should reject names, attributes, function calls, and other Python constructs. Provide the implementation and explain your parsing strategy (tokenization or ast parsing).
HardTechnical
76 practiced
Implement a simple Bloom filter class in Python that supports add(item) and probably_contains(item), with configurable size and number of hash functions. Explain how false positive rate depends on parameters and show example calculations for choosing size when expecting 1M items with 1% false positive rate.
MediumTechnical
80 practiced
Implement a Python decorator retry(max_attempts=3, backoff_factor=0.5) that retries a function on exceptions with exponential backoff. The decorator should be usable with and without arguments, preserve function metadata (name, docstring), and allow specifying which exception types to catch. Provide example usage for a flaky network call.
MediumTechnical
75 practiced
Write pytest unit tests for a function normalize_text(s: str) -> str that should perform: trimming, collapse multiple whitespace to single spaces, lowercasing, and removing non-ASCII control characters. Provide tests for normal cases, edge cases (empty string, very long input), and malicious input (long sequence of whitespace). Show how to parametrize tests and run them.

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.