In Flask, to register a function to run before each request, you would use the ____ decorator.

  • @before_render
  • @before_request
  • @pre_request
  • @request_handler
In Flask, the @before_request decorator is used to register a function that runs before each request to the application. This is often used for tasks like setting up database connections or authentication checks.

In Flask, what is the purpose of the route() decorator?

  • It authenticates user access to certain routes
  • It defines the routing logic for the application
  • It defines the schema for the database
  • It specifies the URL for the static files
In Flask, the @app.route() decorator is used to define the routing logic for the application. It associates a URL with a Python function, allowing you to determine what should happen when a user accesses a particular URL.

In machine learning, ____ is a technique used to choose the hyperparameters for a given model.

  • Cross-Validation
  • Feature Engineering
  • Gradient Descent
  • Hyperparameter Tuning
Hyperparameter tuning is the process of selecting the optimal hyperparameters for a machine learning model to achieve the best performance. It is a crucial step in model development.

In Matplotlib, how do you add a title to a plot?

  • plt.add_title()
  • plt.plot_title()
  • plt.set_title()
  • plt.title()
In Matplotlib, you add a title to a plot using the plt.title() function. This function takes a string as an argument and sets it as the title of the plot. Titles are essential to provide context and information about the content of the plot.

In Matplotlib, the ____ function is used to add text annotations in arbitrary locations of the plot.

  • annotate
  • caption
  • label
  • text
In Matplotlib, the annotate function is used to add text annotations in arbitrary locations of the plot. These annotations can be used to provide additional information about data points, labels, or other details on the plot.

The ____ method in the unittest framework is used to compare whether two values are equal.

  • assertEqual
  • checkEquality
  • compareValues
  • isEqual
In the unittest framework, the assertEqual method is used to compare whether two values are equal. It is commonly used within test cases to verify that the actual output matches the expected output. If the values are not equal, it raises an assertion error.

The ____ method in the unittest framework is used to immediately terminate a test and mark it as failed.

  • assertFail()
  • assertFailTest()
  • fail()
  • failTest()
In the unittest framework, the fail() method is used to immediately terminate a test and mark it as failed. This is useful when you want to explicitly indicate a test failure.

The ____ method is used to initialize the object’s attributes in a class.

  • construct
  • create
  • init
  • new
In Python, the __init__ method is a special method (also known as a constructor) used to initialize the attributes of an object when an instance of a class is created. It allows you to set the initial state of the object.

The ____ method is used to pre-fetch the next value of a generator object.

  • await
  • next
  • yield
  • yieldNext
The correct method to pre-fetch the next value of a generator object is the next method. It allows you to advance the generator and obtain the next yielded value.

The ____ method returns the number of occurrences of a substring in the given string.

  • count()
  • find()
  • index()
  • search()
The count() method is used to find the number of occurrences of a substring in a given string. It returns an integer representing the count.