Consider a loop that processes each item in a list. If you want to skip processing for specific items and continue with the next one, which statement would you use?

  • break
  • continue
  • pass
  • skip
To skip processing for specific items in a loop and continue with the next one, you would use the 'continue' statement. It allows you to bypass the current iteration and move on to the next item in the loop.

Which method would you use to get a list of all the keys in a dictionary?

  • d.items()
  • d.keylist()
  • d.keys()
  • d.values()
To get a list of all the keys in a dictionary 'd', you would use the d.keys() method. It returns a list of all the keys present in the dictionary.

What happens when a function doesn't have a return statement?

  • It raises an error
  • It returns 0
  • It returns None
  • It returns a blank string
When a function lacks a return statement, it automatically returns None. This indicates that the function doesn't return a specific value.

Which of the following tuple methods returns the number of times a specified value appears in the tuple?

  • count()
  • find()
  • index()
  • length()
The count() method is used to determine how many times a specified value appears in a tuple. It's a useful tool for counting occurrences of elements in tuples.

To create a module in Python, you need to write your functions, classes, and variables in a _______ file.

  • .module
  • .pack
  • .py
  • .txt
To create a module in Python, you need to write your functions, classes, and variables in a '.py' file, which is a Python source code file.

Which of the following is a modulus operator in Python?

  • %
  • &
  • *
  • ~
The '%' symbol in Python is the modulus operator. It returns the remainder when the first operand is divided by the second operand. For example, 10 % 3 returns 1 because 10 divided by 3 leaves a remainder of 1.

Which of the following is not typically a use case for the with statement in Python?

  • Creating a context manager
  • Managing database connections
  • Opening and closing files
  • Performing arithmetic calculations inside a loop
The with statement is typically used for resource management, such as file handling or database connections. It is not meant for performing arithmetic calculations.

What's the primary benefit of using tuples as keys in dictionaries over lists?

  • Tuples are faster to access.
  • Tuples are immutable.
  • Tuples are more memory-efficient.
  • Tuples guarantee order.
The primary benefit of using tuples as keys in dictionaries is that tuples are immutable, while lists are not. This immutability ensures that the keys won't change, making tuples suitable for use as dictionary keys. Lists can't be used as keys because they can change.

_______ is a built-in Python function that dynamically loads a module into the current namespace.

  • import
  • include
  • load
  • require
The import statement is used to dynamically load a module into the current Python namespace. It allows you to access functions, classes, and variables defined in the imported module. This dynamic loading is crucial for code modularity and reusability, enabling you to use code from different modules in your Python programs.

If you want to overload the less than (<) operator for a class, you will define the _______ method in your class.

  • __compare__
  • __less__
  • __lessthan__
  • __lt__
To overload the less than (<) operator for a class, you define the __lt__ (less than) method in your class. This method is called when the "<" operator is used with objects of the class.