Already Graded A
What is a set in Python?
✔✔A set is an unordered collection of unique elements, defined by using curly braces, e.g.,
`my_set = {1, 2, 3}`.
How do you reverse a string in Python?
✔✔You can reverse a string in Python using slicing, e.g., `my_str[::-1]`.
What is the `zip()` function used for in Python?
✔✔The `zip()` function is used to combine multiple iterables into a single iterator of tuples.
How do you create a class in Python?
✔✔A class in Python is created using the `class` keyword, followed by the class name, e.g.,
`class MyClass:`.
What is the purpose of the `yield` keyword in Python?
1
, ✔✔The `yield` keyword is used to return a generator, allowing a function to return a value and
resume its state when called again.
How do you find the length of a string in Python?
✔✔You can find the length of a string using the `len()` function, e.g., `len(my_str)`.
What is list comprehension in Python?
✔✔List comprehension is a concise way to create lists, using a single line of code with an
expression and a `for` loop.
How do you sort a list in Python?
✔✔You can sort a list using the `sort()` method (for in-place sorting) or the `sorted()` function
(for creating a new sorted list).
How do you remove all items from a list in Python?
✔✔You can remove all items from a list using the `clear()` method, e.g., `my_list.clear()`.
How do you create a dictionary in Python?
2