Latest Version Graded A+
What is the difference between a tuple and a list in Python?
✔✔A tuple is immutable, meaning its elements cannot be modified after creation, while a list is
mutable.
How do you create a comment in Python?
✔✔By using the `#` symbol before the comment text.
What is the purpose of the `range()` function in Python?
✔✔It generates a sequence of numbers, commonly used in loops for iteration.
How can you handle exceptions in Python?
✔✔By using the `try`, `except`, and optionally `finally` blocks.
What does the `import` statement do in Python?
✔✔It is used to include external modules or libraries into the current program.
1
,How do you create a dictionary in Python?
✔✔By using curly braces `{}` with key-value pairs separated by colons.
What is the difference between `==` and `is` in Python?
✔✔`==` checks if the values of two objects are equal, while `is` checks if two objects refer to the
same memory location.
What is the result of `2**3` in Python?
✔✔8, because it calculates 2 raised to the power of 3.
What is a lambda function in Python?
✔✔An anonymous function defined with the `lambda` keyword, used for short, single-
expression functions.
How do you append an item to a list in Python?
✔✔By using the `append()` method on the list object.
2
,What does the `strip()` method do in Python?
✔✔It removes leading and trailing whitespace from a string.
How do you read a file in Python?
✔✔By using the `open()` function and calling the `read()` method on the file object.
What is the difference between `break` and `continue` in Python loops?
✔✔`break` exits the loop entirely, while `continue` skips the current iteration and proceeds with
the next one.
How do you create a class in Python?
✔✔By using the `class` keyword followed by the class name and a colon.
What does the `__init__()` method do in a Python class?
✔✔It is the constructor method, called when an object of the class is instantiated, to initialize the
object's attributes.
What is the purpose of the `self` keyword in a Python class?
3
, ✔✔`self` refers to the current instance of the class, used to access its attributes and methods.
How do you check if a key exists in a Python dictionary?
✔✔By using the `in` keyword, such as `key in dictionary`.
What is the output of `print("Hello"[0])` in Python?
✔✔`H`, because it accesses the first character of the string.
How do you concatenate two strings in Python?
✔✔By using the `+` operator.
What is the `map()` function used for in Python?
✔✔It applies a given function to all items in an iterable (like a list or tuple).
How can you convert a string to an integer in Python?
✔✔By using the `int()` function.
What is the purpose of the `filter()` function in Python?
4