How can you determine the index of the first occurrence of value x in a tuple?

  • find(x)
  • first_index(x)
  • get_index(x)
  • index(x)
You can determine the index of the first occurrence of value x in a tuple using the index(x) method. It returns the index of the first occurrence of the specified value.

Which decorator in Python is commonly used to define a method as a class property getter?

  • @get
  • @getter
  • @method
  • @property
To define a method as a class property getter in Python, the @property decorator is commonly used. This decorator allows you to access a method like an attribute, making it a clean way to implement read-only properties in classes.

When iterating over a dictionary's items, each item is presented as a _______.

  • Key
  • Key-Value Pair
  • Tuple
  • Value
When iterating over a dictionary, each item is presented as a key-value pair (a tuple), where the key represents the dictionary's key, and the value represents the corresponding value associated with that key.

The file method _______ is used to obtain the current position of the file read/write pointer.

  • current_position()
  • file_position()
  • get_position()
  • tell()
The tell() method in Python's file handling is used to obtain the current position of the file read/write pointer. It returns an integer representing the current position in bytes. This is crucial when you want to navigate through a file or keep track of where you are when reading or writing data.

Which Python module provides functionality to read and write data in CSV format?

  • csv
  • dataio
  • table
  • textfile
The csv module in Python provides functionality for reading and writing data in CSV (Comma-Separated Values) format, making it a popular choice for working with spreadsheet-like data.

Which memory management technique does Python primarily utilize?

  • Garbage Collection (GC)
  • Manual Memory Management (malloc/free)
  • Reference Counting
  • Stack Allocation
Python primarily utilizes Garbage Collection (GC) for memory management. It automatically deallocates memory occupied by objects that are no longer in use, making memory management more convenient and reducing the risk of memory leaks.

In list comprehensions, the ______ keyword can be used to filter out specific values.

  • except
  • filter
  • for
  • if
In list comprehensions, the if keyword is used to filter out specific values based on a condition. This allows you to include or exclude elements based on a specified criterion.

How do you specify an alternative condition to be checked in Python if the previous condition was false?

  • elif
  • else if
  • elseif
  • elseifcondition
To specify an alternative condition in Python when the previous condition is false, you use the 'elif' keyword. It allows you to check another condition if the preceding 'if' condition is false.

To make the custom objects of a class iterable using a for loop, one should implement the _______ and _______ methods.

  • __for__ and __loop__
  • __iter__ and __next__
  • __iterator__ and __iter__
  • __next__ and __previous__
To enable custom objects of a class to be iterable, you need to implement the __iter__ and __next__ methods. The __iter__ method returns the iterator object itself, and the __next__ method defines how to iterate over the object.

The concept where the inner function captures and remembers the enclosing function's local state is called _______.

  • Abstraction
  • Closure
  • Encapsulation
  • Inheritance
The concept where the inner function captures and remembers the enclosing function's local state is called a Closure. Closures are used in Python to create functions with behavior that depends on the variables in the enclosing function.

In Python, every function returns a value. If no return statement is present, it returns _______ by default.

  • 0
  • FALSE
  • None
  • TRUE
In Python, if no return statement is present in a function, it returns 'None' by default. 'None' is a special value representing the absence of a value.

In which block do you write the code that might raise an exception?

  • except
  • finally
  • raise
  • try
You write the code that might raise an exception in the try block in Python. The try block contains the code that you want to monitor for exceptions. If an exception occurs, it is caught by the except block.