When using TensorFlow or PyTorch, the ____ method is used to load a pre-trained model.

  • create_model
  • import_model
  • initialize_model
  • load_model
When working with deep learning frameworks like TensorFlow or PyTorch, you typically use the load_model method to load a pre-trained model from a file. This allows you to reuse a model that has been previously trained on a large dataset.

When using the unittest framework, which method is executed before each test method is run?

  • beforeTest()
  • init()
  • setUp()
  • setUpClass()
In the unittest framework, the setUp() method is executed before each test method is run. This method is used to set up any preconditions or resources needed for the test.

Which algorithm would you use to find the shortest path in an unweighted graph?

  • Bellman-Ford algorithm
  • Breadth-First Search (BFS)
  • Depth-First Search (DFS)
  • Dijkstra's algorithm
In an unweighted graph, the shortest path can be found using Breadth-First Search (BFS). BFS explores the graph level by level, ensuring that the first time you reach a node is by the shortest path.

Which algorithmic paradigm divides the problem into subproblems and solves each one independently?

  • Backtracking
  • Divide and Conquer
  • Dynamic Programming
  • Greedy
The divide and conquer paradigm breaks down a problem into smaller subproblems, solves each subproblem independently, and then combines their solutions to form the solution to the original problem. It's commonly used in algorithms like merge sort and quicksort.

When creating a test case in the unittest framework, which method is used to contain the individual tests that the test runner will execute?

  • runTest
  • setUp
  • tearDown
  • testMethod
In the unittest framework, individual test methods should start with the word "test" (e.g., test_something). These methods contain the actual test logic that the test runner executes.

When debugging, the ____ command in Pdb is used to print the value of an expression.

  • inspect
  • p
  • print
  • view
In the Python Debugger (pdb), you can use the p or print command to display the value of an expression. This is helpful for inspecting variables and understanding program state during debugging.

When defining a custom exception, it should typically be derived from the built-in ____ class.

  • CustomException
  • Error
  • Exception
  • Throwable
When defining custom exceptions in many programming languages, including Python and Java, it's a best practice to derive them from a built-in exception class like 'Exception.' This allows your custom exception to inherit essential exception handling features.

When designing a RESTful API, how should you handle versioning of the API?

  • Do not version the API
  • Hardcode the version in the API endpoints
  • Include the version in the URL (e.g., /v1/resource)
  • Use a header like "X-API-Version"
The recommended way to handle API versioning in RESTful APIs is by including the version in the URL. This ensures backward compatibility and makes it clear which version of the API a client is using. The other options are not considered best practices.

When implementing a recursive algorithm, what is crucial to avoid infinite recursion?

  • A base case
  • A high stack size
  • A loop
  • Global variables
In a recursive algorithm, it's crucial to have a base case that defines when the recursion should stop. Without a base case, the algorithm will keep calling itself indefinitely, leading to infinite recursion and a stack overflow error.

When integrating a Python back-end with a front-end form, how can you secure the application against Cross-Site Request Forgery (CSRF) attacks?

  • Disable JavaScript to prevent malicious form submissions.
  • Use a unique token with each form submission and verify it on the server.
  • Use HTTPS to encrypt form data.
  • Validate user input on the front-end before submission.
To secure an application against CSRF attacks, you should use a unique token (CSRF token) with each form submission. This token is generated on the server and verified on the server to ensure that the request is legitimate and not forged by a malicious attacker.