ANSWERS GRADED A+
How do you write a Python script that runs indefinitely?
✔✔A Python script can run indefinitely by using an infinite loop, such as `while True:`.
What happens if you try to access an index that is out of range in a Python list?
✔✔Accessing an index that is out of range in a list raises an `IndexError` in Python.
Can you modify the elements of a tuple in Python?
✔✔No, tuples are immutable, so their elements cannot be modified once they are created.
What is a lambda function in Python?
✔✔A lambda function is a small anonymous function defined using the `lambda` keyword.
How do you handle exceptions in Python?
✔✔Exceptions in Python are handled using the `try` and `except` block.
1
,What does the `continue` statement do in a loop?
✔✔The `continue` statement skips the current iteration of the loop and moves to the next
iteration.
How can you check if a value contains only digits in Python?
✔✔You can use the `isdigit()` method to check if a value contains only digits.
What is the difference between a shallow copy and a deep copy in Python?
✔✔A shallow copy creates a new object but does not recursively copy nested objects, while a
deep copy creates a completely independent object, copying everything recursively.
How do you combine two values in Python?
✔✔Values in Python can be combined using the `+` operator.
What does `enumerate()` do in Python?
✔✔The `enumerate()` function adds a counter to an iterable and returns it as an enumerate
object.
2
, What is the purpose of `global` keyword in Python?
✔✔The `global` keyword allows you to modify a global variable inside a function.
How do you get the current time in Python?
✔✔You can get the current time using the `datetime` module.
What is the purpose of the `pass` statement in Python?
✔✔The `pass` statement is a placeholder used when no action is needed.
What does `range()` function do in Python?
✔✔The `range()` function generates a sequence of numbers, which can be used in loops.
How do you check the type of a variable in Python?
✔✔You can use the `type()` function to check the type of a variable.
What is list comprehension in Python?
✔✔List comprehension is a concise way to create lists using a single line of code.
3