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
0 practiced
Production CSV files come with inconsistent encodings and occasionally produce UnicodeDecodeError during training runs. As an ML engineer, propose a robust Python 3 strategy to detect and handle encodings, including runtime detection, fallback encodings, safe decoding with errors handlers, logging, and testing to avoid data corruption. Mention standard library tools and pragmatic fallbacks.
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.
MediumTechnical
0 practiced
Explain why it is unsafe to unpickle data from untrusted sources in Python. Provide safe alternatives for serializing ML artifacts and a short Python 3 example showing how to write and read newline-delimited JSON (ndjson) as a safer option than pickle for simple data records.
MediumTechnical
0 practiced
Implement a Python 3 context manager class 'timed_resource' that can be used in a with statement to open a resource (for example a file object) and measure elapsed time of the block. The context manager must ensure resources are closed properly even if exceptions occur and must return the opened resource from __enter__. Provide the class and a short usage example.
HardTechnical
0 practiced
Write a Python 3 utility function 'total_size(obj)' that estimates the total memory footprint of a nested Python object graph (dicts, lists, tuples, sets, and objects with __dict__) by recursively summing sys.getsizeof while avoiding double-counting shared objects. Describe limitations of sys.getsizeof and how you would improve accuracy for objects that own external buffers like numpy arrays.

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.