You can use the 'try...finally' block in Python to ensure that the database connection is always closed.

  • Implement a custom function to manage connections
  • Manually close the connection in each place
  • Rely on Python's automatic garbage collection
  • Use a context manager like 'with' statements
The 'try...finally' block ensures that the database connection is closed even if an exception occurs. It's a robust way to manage resource cleanup.

Which Python data type is used to represent whole numbers?

  • bool
  • float
  • int
  • str
The 'int' data type in Python is used to represent whole numbers, both positive and negative, without any fractional part.

What do you call a function defined inside another function in Python?

  • Child function
  • Inner function
  • Nested function
  • Sub function
A function defined inside another function in Python is called an 'Inner function' or 'Nested function.' They have access to the variables of the enclosing function.

Which keyword is used in Python to check a condition?

  • check
  • if
  • then
  • verify
In Python, the 'if' keyword is used to check a condition. It allows you to execute a block of code if the condition is true.

When working with large files, why might the readlines() method not be the most memory-efficient?

  • It doesn't work with large files
  • It lacks support for binary file formats
  • It reads the entire file into memory
  • It's not available in Python
The 'readlines()' method reads the entire file into memory, which can be inefficient for large files, as it can lead to memory consumption issues. It's better to use methods like 'readline()' or iterate over the file to process it line by line.

Sets in Python are _______ which means they cannot contain duplicate elements.

  • immutable
  • mutable
  • ordered
  • unhashable
Sets in Python are 'immutable,' which means they cannot contain duplicate elements. Once a set is created, you cannot change its elements, but you can add or remove elements from it.

A variable name in Python cannot start with a _______.

  • Letter
  • Number
  • Special
  • Underscore
In Python, variable names cannot start with a number, as they must begin with a letter or an underscore (_).

What is the correct sequence of blocks in a conditional statement that uses all three components: if, elif, and else?

  • if, elif, else
  • if, else, elif
  • else, if, elif
  • elif, if, else
In Python, the correct sequence in a conditional statement that uses all three components is if, followed by one or more elif blocks, and finally, an optional else block.

What potential issue might arise from relying on the value of the name attribute in a module that is dynamically imported using functions like import()?

  • Circular Import
  • ImportError
  • ModuleNotFoundError
  • NameError
Relying on the name attribute in a dynamically imported module can lead to circular imports. Circular imports can create a situation where two or more modules depend on each other, causing potential issues and making the code harder to maintain.

The Python type(_______) would return .

  • Text
  • character
  • str
  • string
The Python 'type()' function checks the type of an object. To return '', you would use 'type(str)'.