and Answers Graded A+
What is the output of `print(2 ** 3)`?
✔✔ The output is `8`, as `**` is the exponentiation operator in Python.
How can you check if a number is even in Python?
✔✔ Use the modulo operator, like `if num % 2 == 0:`.
What is the difference between `is` and `==` in Python?
✔✔ `is` checks for object identity, while `==` checks for value equality.
How do you define a function in Python?
✔✔ A function is defined using the `def` keyword, like `def my_function():`.
What does the `range()` function do in Python?
✔✔ The `range()` function generates a sequence of numbers, often used in loops.
1
, How do you create a dictionary in Python?
✔✔ A dictionary is created using curly braces with key-value pairs, like `my_dict = {'key':
'value'}`.
What is a set in Python?
✔✔ A set is an unordered collection of unique elements, like `my_set = {1, 2, 3}`.
What is the purpose of the `__init__` method in a Python class?
✔✔ The `__init__` method is the constructor used to initialize a newly created object.
How do you remove an item from a list in Python?
✔✔ Use the `remove()` method, like `my_list.remove(item)`.
What does the `continue` statement do in a loop?
✔✔ The `continue` statement skips the current iteration of the loop and moves to the next one.
How can you handle multiple exceptions in Python?
2