Core Syntax & Data Types
1. What is the difference between a list and a tuple?
ANSWER ✓ A list is mutable, meaning its elements can be changed after creation
(e.g., my_list.append(5)), and it is defined with square brackets []. A tuple is immutable,
meaning its elements cannot be altered after creation, and it is defined with
parentheses ().
2. What is a dictionary in Python?
ANSWER ✓ A dictionary is an unordered, mutable collection of key-value pairs. Keys
must be unique and of an immutable type (like strings, numbers, or tuples). It is defined
with curly braces {} (e.g., {'name': 'Alice', 'age': 30}).
3. What is string slicing?
ANSWER ✓ String slicing is a syntax for extracting a substring from a string. It uses the
format [start:stop:step]. The start index is inclusive, the stop index is exclusive, and
the step determines the increment.
4. What are f-strings?
ANSWER ✓ f-strings (formatted string literals) are a way to embed expressions inside
string literals for formatting, using a minimal syntax. They are prefixed with f or F and
expressions are written inside curly braces (e.g., f"Hello, {name}!").
5. What is the purpose of the None value?
ANSWER ✓ None is a special constant in Python that represents the absence of a value or
a null value. It is often used as a default return value for functions that do not explicitly
return anything.
6. What is the difference between == and is?
ANSWER ✓ The == operator compares the values of two objects to see if they are equal.
The is operator compares the identity of two objects, checking if they refer to the exact
same object in memory.
7. What is type hinting?
ANSWER ✓ Type hinting is a feature that allows you to indicate the expected data types
of function parameters, return values, and variables (e.g., def greet(name: str) -> str:).
It improves code readability and enables better support from IDEs and static analysis
tools.
, 8. What is a docstring?
ANSWER ✓ A docstring is a string literal that occurs as the first statement in a module,
function, class, or method definition. It is used to document the code and is accessible
via the .__doc__ attribute or the help() function.
9. What is the pass statement used for?
ANSWER ✓ The pass statement is a null operation; it does nothing. It is used as a
placeholder where syntax requires a statement but no code needs to be executed, such
as in stubs for incomplete functions or classes.
10. What is the difference between a shallow copy and a deep copy?
ANSWER ✓ A shallow copy constructs a new compound object and then
inserts references into it to the objects found in the original. A deep copy constructs a
new compound object and then, recursively, inserts copies into it of the objects found in
the original.
Functions & Scope
11. What is a function in Python?
ANSWER ✓ A function is a block of reusable code that is defined using the def keyword
(or lambda for anonymous functions). It is designed to perform a specific task and can
take parameters and return a value.
12. What is the difference between parameters and arguments?
ANSWER ✓ Parameters are the variables listed inside the parentheses in the function
definition. Arguments are the actual values passed to the function when it is called.
13. What are *args and **kwargs?
ANSWER ✓ *args allows a function to accept any number of positional arguments. These
arguments are collected into a tuple. **kwargs allows a function to accept any number of
keyword arguments. These arguments are collected into a dictionary.
14. What is a lambda function?
ANSWER ✓ A lambda function is a small, anonymous function defined with
the lambda keyword. It can have any number of arguments but only one expression,
which is evaluated and returned (e.g., lambda x: x**2).
15. What is a decorator?
ANSWER ✓ A decorator is a design pattern in Python that allows a user to add new
functionality to an existing object (like a function or class) without modifying its
structure. It is a function that takes another function as an argument and returns a
modified function.