General Python Questions
- What is Python?
- Python is a high-level, interpreted programming language with simple syntax.
- Who created Python and when?
- Guido van Rossum created Python in 1991.
- What are Python’s data types?
int,float,str,list,tuple,set,dict,bool.
- What is a Python interpreter?
- A program that executes Python code line by line.
- What is a module in Python?
- A file containing Python code that can be reused, usually with a
.pyextension.
- A file containing Python code that can be reused, usually with a
- How do you import a module in Python?
- Use the
importstatement (e.g.,import math).
- Use the
- What is the difference between a list and a tuple?
- Lists are mutable, while tuples are immutable.
- What is the purpose of Python’s
dir()function?- It lists all attributes and methods of an object.
- How do you comment in Python?
- Use
#for single-line comments and triple quotes (""") for multi-line comments.
- Use
- What are Python’s logical operators?
and,or,not.
- What is the purpose of the
len()function?- It returns the length of a collection or string.
- What is a Python script?
- A Python file with
.pyextension that can be executed.
- A Python file with
- What is the difference between
breakandcontinue?breakexits a loop;continueskips the current iteration.
- How do you create a dictionary in Python?
- Using
{}with key-value pairs (e.g.,{'key': 'value'}).
- Using
- What is Python’s default encoding?
- UTF-8.
- What is the use of the
range()function?- It generates a sequence of numbers.
- How do you check the Python version?
- Use
python --versionorsys.version.
- Use
- What is Python’s
Nonetype?- Represents the absence of a value or null value.
- What is
type()in Python?- It returns the type of an object (e.g.,
type(5)returns<class 'int'>).
- It returns the type of an object (e.g.,
- What is the output of
print(2 ** 3)?8(exponentiation).
Intermediate Python Concepts
- What is the purpose of Python’s
withstatement?- It simplifies resource management (e.g., file handling).
- What is the difference between mutable and immutable types?
- Mutable types can be modified (
list), immutable cannot (tuple,str).
- Mutable types can be modified (
- What is a Python lambda function?
- An anonymous, one-line function defined with
lambda.
- An anonymous, one-line function defined with
- How do you handle exceptions in Python?
- Using
try,except,else, andfinally.
- Using
- What is a Python set?
- An unordered collection of unique elements.
- What is Python’s
*args?- Allows passing a variable number of positional arguments to a function.
- What is Python’s
**kwargs?- Allows passing a variable number of keyword arguments to a function.
- How does Python handle default arguments in functions?
- Default values are assigned using the
=operator.
- Default values are assigned using the
- What is a Python comprehension?
- A compact way to generate lists, sets, or dictionaries (e.g.,
[x**2 for x in range(5)]).
- A compact way to generate lists, sets, or dictionaries (e.g.,
- What is slicing in Python?
- Extracting a portion of a sequence using
[start:stop:step].
- Extracting a portion of a sequence using
- How do you merge dictionaries in Python?
- Use
dict.update()or{**dict1, **dict2}.
- Use
- What is Python’s
zip()function?- Combines multiple iterables into tuples.
- How do you create a class in Python?
- Using the
classkeyword (e.g.,class MyClass:).
- Using the
- What is the purpose of
selfin Python classes?- Refers to the instance of the class.
- What is method overriding?
- Redefining a method in a subclass that exists in the parent class.
- How do you open a file in Python?
- Using
open('filename', 'mode').
- Using
- What is the difference between
read()andreadlines()?read()reads the entire file,readlines()reads line by line.
- What is the
enumerate()function?- Adds an index to an iterable during iteration.
- What is
__init__in Python?- A constructor method used to initialize an object.
- What are Python’s access modifiers?
- Public (
variable), protected (_variable), private (__variable).
- Public (
Team and Leadership-Focused Questions
- How do you ensure code quality?
- Use linters, enforce standards, and review code.
- How do you prioritize tasks in a Python project?
- Assess impact and urgency, and align with business goals.
- What is your approach to debugging?
- Use logs,
pdb, and debugging tools in IDEs.
- Use logs,
- How do you conduct a code review?
- Check for functionality, readability, and adherence to standards.
- What tools do you recommend for testing?
pytest,unittest,mock.
- How do you onboard new team members?
- Provide documentation, mentoring, and small starter tasks.
- How do you ensure deadlines are met?
- Break tasks into milestones and regularly review progress.
- What is your approach to resolving conflicts in a team?
- Foster communication and ensure focus on shared goals.
- How do you decide on a Python library?
- Assess stability, community support, and documentation.
- How do you handle technical debt?
- Address during regular sprints and maintain documentation.
- How do you handle poorly written legacy code?
- Refactor incrementally and add tests.
- What is the role of CI/CD in a Python project?
- Automates testing and deployment, ensuring reliability.
- How do you balance coding and leadership responsibilities?
- Delegate tasks and allocate focused time for coding.
- What metrics do you track in a Python project?
- Code coverage, performance benchmarks, and bug resolution rates.
- How do you mentor juniors in Python?
- Pair programming, code reviews, and regular feedback.
- How do you introduce new technologies?
- Start with pilot
