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
0 practiced
Implement a streaming, one-pass algorithm in Python 3 to compute mean and variance for a numeric column in a CSV file without storing all values (use Welford's algorithm). The function should accept a file path and column name and return (count, mean, variance). Explain numeric stability considerations for very large streams.
EasyTechnical
0 practiced
Explain Python variable scope and the LEGB rule (Local, Enclosing, Global, Built-in). Provide concise code examples illustrating each level and show how to modify an enclosing variable from an inner function using 'nonlocal' and how to modify a global variable using 'global'. Discuss best practices for scope to avoid bugs in ML pipelines.
EasyTechnical
0 practiced
Explain the differences between Python list and tuple. Then implement a Python 3 function that accepts a list of integers and returns a sorted tuple of unique integers. The function signature should be 'def unique_sorted_tuple(nums):'. Discuss why you might return a tuple instead of a list in certain ML infrastructure code.
HardTechnical
0 practiced
Design and implement a Python 3 function 'top_k_frequent(stream, k)' that returns the k most frequent items from a stream of hashable keys. Consider the trade-offs when the stream is too large to keep all counts in memory. Provide an exact in-memory solution suitable for moderate cardinality and outline an approximate approach (algorithms or data structures) for very high cardinality streams.
MediumTechnical
0 practiced
Describe the purpose of Python's with statement and context managers. Provide a concise example of a custom context manager implemented using the contextlib.contextmanager decorator and explain how it differs from implementing __enter__ and __exit__ methods in a class.

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.