Answers with Verified Answers
What is the difference between a list and a tuple in Python?
✔✔ A list is mutable and can be modified after creation, while a tuple is immutable and cannot
be modified.
How do you check the type of a variable in Python?
✔✔ You use the `type()` function, such as `type(x)`.
How can you add an element to a list in Python?
✔✔ You can use the `append()` method, like `my_list.append(10)`.
How do you handle exceptions in Python?
✔✔ You use the `try` and `except` blocks to handle exceptions.
What is a dictionary in Python?
✔✔ A dictionary is an unordered collection of key-value pairs.
1
,How do you access a value in a dictionary?
✔✔ You use the key inside square brackets, like `my_dict['key']`.
What does the `continue` statement do in a loop?
✔✔ The `continue` statement skips the current iteration and moves to the next one.
What is the purpose of the `pass` statement in Python?
✔✔ The `pass` statement is used as a placeholder when a statement is required syntactically but
you do not want to execute anything.
How do you define a function in Python?
✔✔ You use the `def` keyword, followed by the function name and parentheses, such as `def
my_function():`.
What is the output of `print(2 ** 3)`?
✔✔ The output is `8`, since `2 ** 3` calculates 2 raised to the power of 3.
How do you convert a string to an integer in Python?
2
, ✔✔ You use the `int()` function, like `int("123")`.
What is the purpose of the `return` statement in a function?
✔✔ The `return` statement sends a result back to the function's caller.
How do you create a class in Python?
✔✔ You use the `class` keyword, followed by the class name, such as `class MyClass:`.
What is the `__init__` method in Python?
✔✔ The `__init__` method is a special method used to initialize an object when it is created.
How do you create an object of a class in Python?
✔✔ You create an object by calling the class as if it were a function, like `my_object =
MyClass()`.
What is the output of `print('Python' == 'python')`?
✔✔ The output is `False`, since string comparison is case-sensitive.
3