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
Write a Python function top_k_by_key(items, k, key=lambda x: x) that returns the k largest items by a key function but is memory efficient when len(items) is very large (items is an iterator). Use the standard library and explain complexity and memory guarantees.
EasyTechnical
0 practiced
Explain the common pitfall of using mutable default arguments in function definitions. Show an example function that accumulates items using a default list and explain why repeated calls can produce unexpected results. Provide two correct alternatives and discuss which you would prefer in production code.
HardTechnical
0 practiced
Implement an async context manager that acquires and releases an asyncio.Lock and times the duration held, exposing the elapsed time to the caller after the 'async with' block. Provide both the implementation and an example usage where multiple async tasks contend for the lock and their hold times are recorded.
MediumTechnical
0 practiced
Explain Python's import system and module caching behavior. How should you structure a package for an AI project with modules for data, models, and utils to avoid circular imports? Provide examples of relative vs absolute imports and techniques to break import cycles.
EasyTechnical
0 practiced
Describe Python variable naming rules and best practices. Include examples of valid and invalid identifiers, explain PEP 8 recommendations for variable names, and show short code demonstrating multiple assignment, tuple unpacking, and augmented assignment (+=). Finish by describing how clear naming helps in collaborative AI codebases.

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.