Answers Graded A+
How do you handle multiple exceptions in Python?
✔✔You handle multiple exceptions using multiple `except` blocks or a tuple of exceptions in
one block.
What does the `all()` function do?
✔✔The `all()` function returns `True` if all elements in an iterable are true.
What does the `any()` function do?
✔✔The `any()` function returns `True` if at least one element in an iterable is true.
How do you sort a list in Python?
✔✔You sort a list using the `sort()` method or the `sorted()` function.
How do you check if a dictionary key exists?
✔✔You check if a key exists using the `in` keyword, like `key in dict`.
1
,What is the difference between `deepcopy()` and `copy()`?
✔✔`copy()` creates a shallow copy, while `deepcopy()` creates a copy of the object and its
nested structures.
What is indentation in Python?
✔✔Indentation in Python is used to define blocks of code, such as loops, conditionals, and
functions.
How do you create a multiline string in Python?
✔✔You create a multiline string using triple quotes (`"""` or `'''`).
What is the purpose of the `pass` statement in Python?
✔✔The `pass` statement is used as a placeholder to create an empty block of code.
How do you reverse a list in Python?
✔✔You reverse a list using the `reverse()` method or slicing like `list[::-1]`.
What does the `pop()` method do in Python?
2
,✔✔The `pop()` method removes and returns the last element of a list, or an element at a
specified index.
How do you merge two dictionaries in Python?
✔✔You merge dictionaries using the `update()` method or the `{**dict1, **dict2}` syntax.
What is a lambda function in Python?
✔✔A lambda function is a small anonymous function defined using the `lambda` keyword.
How do you create a range of numbers in Python?
✔✔You use the `range()` function to create a sequence of numbers.
What is the difference between `==` and `=` in Python?
✔✔`==` is used for comparison, while `=` is used for assignment.
How do you generate a list of squares using a loop?
✔✔You can use a list comprehension like `[x**2 for x in range(n)]`.
3
, How do you remove duplicates from a list in Python?
✔✔You convert the list to a set using `set()` and then back to a list.
What is the purpose of the `enumerate()` function?
✔✔The `enumerate()` function adds a counter to an iterable, returning both the index and the
value.
How do you check the type of a variable in Python?
✔✔You use the `type()` function to check the type of a variable.
What does the `zip()` function do?
✔✔The `zip()` function combines two or more iterables into tuples.
How do you unpack a tuple in Python?
✔✔You unpack a tuple by assigning its elements to variables, like `a, b = my_tuple`.
What is the difference between `is` and `==` in Python?
✔✔`is` checks for object identity, while `==` checks for value equality.
4