Post‐test exams - up1/course-python-workshop GitHub Wiki

Post-test exams

1. What is the primary difference between a list and a tuple in Python ?

  • A. Lists are immutable; tuples are mutable
  • B. Lists are mutable; tuples are immutable
  • C. Lists can contain different data types; tuples cannot
  • D. Tuples consume more memory than lists

2. How can you handle exceptions in Python ?

  • A. Using try and except blocks
  • B. Using catch and finally blocks
  • C. Using do and while blocks
  • D. Using error and handle blocks

3. What is the difference between is and == in Python ?

  • A. is compares values; == compares object identities
  • B. is compares object identities; == compares values
  • C. They are the same
  • D. is is used for strings; == is used for numbers

4. What is the output of the following code ?

a = [1, 2, 3, 4]
print(a[::2])
  • A. [1, 2]
  • B. [2, 4]
  • C. [1, 3]
  • D. [1, 4]​

5. What is the purpose of the name variable in Python ?

  • A. To define the name of a function
  • B. To check if the script is being run directly or imported as a module
  • C. To specify the name of the Python file
  • D. To declare a global variable

6. What is the output of the following code?

print(bool('False'))
  • A. True
  • B. False
  • C. None
  • D. Error​

7. In Python, what is a lambda function ?

  • A. A function with no name
  • B. A function that returns multiple values
  • C. A function that takes no arguments
  • D. A function defined inside a class

8. How do you create a virtual environment in Python ?

  • A. python -m venv env
  • B. virtualenv env
  • C. pip install virtualenv
  • D. python create_env​

9. What is the purpose of the super() function in Python ?

  • A. To call the constructor of the parent class
  • B. To return the superclass of the object
  • C. To determine the method resolution order
  • D. To access private attributes of the parent class

10. In Python, what is the purpose of the with statement when opening a file ?

  • A. To open a file and close it manually
  • B. To open a file and automatically close it after the nested block of code
  • C. To open multiple files simultaneously
  • D. To handle file exceptions

11. What is normalization in database design ?

  • A. The process of duplicating data across tables
  • B. Organizing data to reduce redundancy and improve integrity
  • C. Combining multiple tables into one
  • D. Removing all indexes from the database

12. How can you prevent SQL injection when using Python to interact with a MySQL database ?

  • A. By using string concatenation to build queries
  • B. By using parameterized queries with placeholders
  • C. By limiting user input length
  • D. By encrypting the database

13. In database design, what does the term "denormalization" refer to ?

  • A. The process of splitting a table into multiple tables
  • B. The process of combining tables to improve read performance
  • C. Removing all constraints from a table
  • D. Converting a database to a flat-file structure

14. What is the role of an index in a database ?

  • A. To enforce referential integrity
  • B. To improve the speed of data retrieval operations
  • C. To store backup copies of data
  • D. To define relationships between tables

15. Which of the following is a benefit of using Object-Relational Mapping (ORM) in Python ?

  • A. Direct execution of raw SQL queries
  • B. Automatic translation between database tables and Python objects
  • C. Improved performance over direct database connections
  • D. Elimination of the need for database migrations

16. What is the purpose of input validation in REST APIs ?

  • A. To ensure that the server responds quickly
  • B. To verify that incoming data meets expected formats and constraints
  • C. To authenticate users
  • D. To optimize database queries

17. Which HTTP status code indicates that the client must authenticate itself to get the requested response ?

  • A. 401 Unauthorized
  • B. 403 Forbidden
  • C. 404 Not Found
  • D. 400 Bad Request

18. In RESTful design, what does it mean for an operation to be idempotent ?

  • A. The operation can be performed only once
  • B. The operation has the same result regardless of how many times it is performed
  • C. The operation cannot be undone
  • D. The operation requires authentication​

19. In RESTful API design, what is the recommended way to handle long-running operations ?

  • A. Use synchronous processing
  • B. Return a 202 Accepted status with a link to check the status
  • C. Increase the server timeout
  • D. Use multiple threads

20. Which of the following is a common tool for testing RESTful APIs ?

  • A. Selenium
  • B. Postman
  • C. Jenkins
  • D. Docker