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.

In a for-loop iterating through a list, if a specific condition is met and you want to skip the remaining code in the current iteration but not exit the loop, you would use the _______ statement.

  • Break
  • Continue
  • Pass
  • Skip
The 'continue' statement is used to skip the remaining code in the current iteration of a loop and move to the next iteration without exiting the loop. So, you would use 'Continue.'

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)'.

You're reviewing a Python class and notice that many attributes are accessed and modified directly, without any checks. What could be introduced to provide controlled access and validation to these attributes?

  • Creating a separate module to handle attribute access and modification.
  • Defining the attributes within a function for validation.
  • Encapsulating the attributes by making them private and providing getter and setter methods.
  • Using global variables to track and validate attribute changes.
To provide controlled access and validation to attributes, you should encapsulate the attributes by making them private and providing getter and setter methods to enforce checks and validation.

You're working with a dictionary where keys are country names and values are their capitals. You want to invert this dictionary. What potential issue might you encounter?

  • No potential issue, dictionaries are always invertible.
  • Potential issue: Overwriting keys if country names are not unique.
  • Potential issue: Overwriting values if capitals are not unique.
  • Potential issue: Python dictionaries cannot be inverted.
When inverting a dictionary, if the values (capitals) are not unique, you may encounter an issue where some values get overwritten. This results in the loss of information, as multiple countries may have the same capital. Inverting dictionaries assumes unique values for keys in the original dictionary.