with Verified Solutions
How do you add an element to a set in Python?
✔✔You use the `add()` method to add an element to a set, e.g., `my_set.add(5)`.
What does the `sort()` method do to a list?
✔✔The `sort()` method sorts the list in place, modifying the original list into an ascending order.
How do you combine two dictionaries in Python?
✔✔You can combine two dictionaries using the `update()` method or the `**` unpacking
operator:
```python
dict1.update(dict2)
```
How can you make a copy of a list without modifying the original one?
✔✔You can use the `copy()` method or slice the list: `my_list.copy()` or `my_list[:]`.
1
, What is a function's return value?
✔✔A return value is the output that a function gives after executing its code, which can be used
elsewhere in the program.
How do you define a class in Python?
✔✔You define a class using the `class` keyword, followed by the class name, e.g.,
```python
class Car:
def __init__(self, make, model):
self.make = make
self.model = model
```
How do you check the type of an object in Python?
✔✔You can use the `type()` function to check the type of an object, e.g., `type(my_variable)`.
What does the `range()` function return?
2