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
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).
EasyTechnical
0 practiced
Given the following loop that processes a list of filenames:
python
i = 0
for f in filenames:
    print(i, f)
    i += 1
Rewrite this loop using Python idiomatic constructs to make it clearer and safer for edge cases. Explain the benefits of your version (readability, avoiding off-by-one errors), and show how to iterate in reverse order with indexes when needed.
EasyTechnical
0 practiced
Write a short Python script using only the standard library to read a CSV file of rows (columns: id,name,value), convert each row to JSON objects, and write them as newline-delimited JSON (JSONL). Show how your code handles malformed rows gracefully and how it streams data for memory efficiency (assume file size may be many GB).
HardTechnical
0 practiced
Create a decorator retry that can be used both with and without arguments:
- @retry- @retry(max_attempts=5)
It should retry the wrapped function on specified exceptions, optionally log each retry, and respect a maximum attempts value. Provide the implementation and explain how it detects whether it was called with arguments or directly as a decorator.
HardTechnical
0 practiced
You need to safely load and sanitize JSON metadata received from untrusted third-party sources before using it to set model configuration. Describe a secure parsing strategy in Python: validating schema, limiting recursion depth and size, avoiding code execution, and preventing prototype-like pollution. Provide a short code example that validates required fields and safely coerces types.

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.