Pre‐test exam - up1/course-python-workshop GitHub Wiki

Pre-test exam

1. Which of the following is a valid Python variable name ?

  • A. 2nd_var
  • B. my-var
  • C. my_var
  • D. my var

2. Which data type is immutable in Python ?

  • A. List
  • B. Dictionary
  • C. Tuple
  • D. Set

3. What does the range(5) function return in a loop ?

  • A. 1, 2, 3, 4, 5
  • B. 0, 1, 2, 3, 4
  • C. 0, 1, 2, 3, 4, 5
  • D. 1, 2, 3, 4

4. What is the output of the following ?

x = [i for i in range(3)]
print(x)
  • A. [1, 2, 3]
  • B. [0, 1, 2, 3]
  • C. [0, 1, 2]
  • D. 0 1 2

5. What will this dictionary comprehension return ?

{i: i*i for i in range(3)}
  • A. {1: 1, 2: 4, 3: 9}
  • B. {0: 0, 1: 1, 2: 4}
  • C. 0 1 2
  • D. [0, 1, 4]

6. What is self in a Python class method ?

  • A. global variable
  • B. keyword to refer to parent class
  • C. reference to the current instance
  • D. decorator

7. What does open('file.txt', 'r') do ?

  • A. Open file for writing
  • B. Open file in append mode
  • C. Open file for reading
  • D. Deletes the file

8. Which HTTP method is used for retrieving data from a REST API ?

  • A. POST
  • B. PUT
  • C. GET
  • D. DELETE

9. What is a class in Python ?

  • A. function
  • B. loop
  • C. blueprint for creating objects
  • D. package

10. What is the purpose of init() in a class ?

  • A. It initializes the class
  • B. It deletes the object
  • C. It prints class attributes
  • D. It imports the class

11. What is a response code for "Create data success" ?

  • A. 201
  • B. 500
  • C. 200
  • D. 302

12. What does NumPy primarily handle ?

  • A. Web scraping
  • B. Plotting graphs
  • C. Numerical computation
  • D. APIs

13. Which of the following is a list in Python ?

  • A. {1, 2, 3}
  • B. [1, 2, 3]
  • C. (1, 2, 3)
  • D. <1, 2, 3>

14. What is matplotlib.pyplot used for ?

  • A. Data cleaning
  • B. Image processing
  • C. Data visualization
  • D. Web scraping

15. What does the super() function do in Python ?

  • A. Calls the init method of the base class
  • B. Deletes the current instance
  • C. Returns the string representation of the object
  • D. Calls the destructor of the base class

16. What is the primary difference between the PUT and POST HTTP methods ?

  • A. PUT is idempotent; POST is not
  • B. POST is idempotent; PUT is not
  • C. PUT is used for deleting resources; POST is used for creating resources
  • D. There is no difference between PUT and POST

17. 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​

18. Which Python library is officially provided by MySQL for database integration ?

  • A. pymysql
  • B. mysql-connector-python
  • C. MySQLdb
  • D. sqlalchemy

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

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

20. What is the default port number for MySQL that should be used when connecting via Python ?

  • A. 3306
  • B. 5432
  • C. 1521
  • D. 1433
⚠️ **GitHub.com Fallback** ⚠️