To merge two dictionaries d1 and d2, you can use d1.______(d2).

  • combine
  • join
  • merge
  • update
You can merge two dictionaries in Python by using the update() method on d1, passing d2 as an argument. This will update d1 with the key-value pairs from d2.

The _______ operator is used to determine if two values are not equal in Python.

  • Difference
  • Inequality
  • Not Equal
  • Unequal
The '!=' operator is used in Python to determine if two values are not equal. It returns True if the values are not equal, and False if they are.

Which method is used to append an item to the end of the list?

  • add()
  • append()
  • extend()
  • insert()
The method used to append an item to the end of a list in Python is append(). It adds the element to the end of the list.

How does Python treat a directory containing init.py compared to one without it?

  • Python raises an error for both cases.
  • Python recognizes the one with init.py as a package.
  • Python recognizes the one without init.py as a package.
  • Python treats both directories the same way.
Python treats a directory containing __init__.py as a package. It allows you to import modules and sub-packages from within it. A directory without __init__.py is treated as a regular directory, and Python won't consider it a package, limiting its use for organizing code.

Which statement is used to skip the remainder of the code inside the current loop iteration and move to the next iteration?

  • continue
  • jump
  • pass
  • skip
The 'continue' statement is used to skip the remaining code inside the current loop iteration and move to the next iteration of the loop. It allows you to bypass specific conditions or processing in the loop.

Which of the following is the correct way to define a function in Python?

  • def my_function():
  • define_function my_function():
  • func my_function():
  • function my_function():
The correct way to define a function in Python is as follows: 'def my_function():'. The 'def' keyword is used to define a function, followed by the function name and parentheses.

The statement for x in y where y is a data structure, x refers to _______ of the data structure in each iteration.

  • Elements/Items
  • Keywords
  • Length/Index
  • Type
In the statement for x in y, where y is a data structure, x refers to the elements or items of the data structure in each iteration of the loop.

You have a directory with multiple Python script files. You want it to be recognized as a Python package. Which file would you need to add to this directory?

  • init.py
  • main.py
  • package.py
  • setup.py
To make a directory recognized as a Python package, you need to add an 'init.py' file. This file can be empty but is necessary for package recognition.

How can you capture the error message of an exception into a variable?

  • Using the 'get_error_message()' method
  • Using the 'message' keyword
  • Using the 'print()' statement
  • Using the 'try' block and 'except'
To capture the error message of an exception into a variable, you can use a 'try' block and an 'except' clause. Inside the 'except' block, you can access the error message using the 'str()' function or by converting the exception object to a string. For example, error_message = str(exception).

How can you prevent specific functions or classes from being imported when the wildcard * is used with import?

  • Define all
  • Use a custom import
  • Use a hidden prefix
  • Use the @noimport decorator
You can prevent specific functions or classes from being imported when the wildcard * is used by defining a special variable named all in the module. all is a list of strings containing the names of symbols that should be imported when using from module import *.