💻
Programming Medium

Intermediate Python

Test your Python knowledge with functions, OOP and data structures!

15 Questions
30s Per Question
0+ Plays
← All Programming Quizzes 📚 Study Guide for this category →
💡 Create account to save scores & earn XP
📋 View All 15 Questions & Answers

1. What does the "pass" statement do in Python?

  • A. Exits the program
  • B. Skips a loop iteration
  • C. Does nothing — acts as a placeholder ✓
  • D. Returns a value

💡 "pass" is a null statement used as a placeholder where code is required syntactically but nothing needs to happen.

2. What is a dictionary in Python?

  • A. A list of sorted items
  • B. A collection of key-value pairs ✓
  • C. A type of loop
  • D. An ordered set

💡 A dictionary stores data as key-value pairs: {"name": "Ali", "age": 25}.

3. What does "import" do in Python?

  • A. Creates a new file
  • B. Exports code
  • C. Loads an external module into the current program ✓
  • D. Deletes a module

💡 import loads external modules: "import math" gives access to math functions like math.sqrt().

4. What is the output of: print(2 ** 8)?

  • A. 16
  • B. 64
  • C. 128
  • D. 256 ✓

💡 ** is the exponentiation operator. 2 ** 8 = 2⁸ = 256.

5. What does "list comprehension" do in Python?

  • A. Deletes a list
  • B. Sorts a list
  • C. Creates a new list by iterating over an existing one ✓
  • D. Merges two lists

💡 List comprehension creates a new list: [x*2 for x in range(5)] → [0, 2, 4, 6, 8].

6. What does the "global" keyword do in Python?

  • A. Creates a new variable
  • B. Imports a module
  • C. Declares a variable inside a function as global ✓
  • D. Deletes a variable

💡 The "global" keyword inside a function allows it to modify a variable defined in the global scope.

7. What is a Python decorator?

  • A. A type of loop
  • B. A function that modifies another function ✓
  • C. A type of variable
  • D. A class method

💡 A decorator is a function that wraps another function to modify or extend its behavior using @decorator syntax.

8. What is a lambda function in Python?

  • A. A class method
  • B. A built-in function
  • C. A type of loop
  • D. A small anonymous function ✓

💡 A lambda is a small anonymous function: lambda x: x + 1. It can have any number of arguments but one expression.

9. What does the "self" parameter in a Python class method refer to?

  • A. The class itself
  • B. The parent class
  • C. The current instance of the class ✓
  • D. A global variable

💡 "self" refers to the current object instance, allowing access to its attributes and methods.

10. What is the purpose of "__init__" in a Python class?

  • A. To delete an object
  • B. To print an object
  • C. To copy an object
  • D. To initialize object attributes when created ✓

💡 __init__ is the constructor method called automatically when a new object is created from a class.

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

  • A. Lists are faster
  • B. Tuples can store more items
  • C. Tuples use {} brackets
  • D. Lists are mutable; tuples are immutable ✓

💡 Lists [] can be changed after creation (mutable). Tuples () cannot be changed (immutable).

12. What is the output of: print("Python"[0])?

  • A. P ✓
  • B. y
  • C. n
  • D. Python

💡 String indexing starts at 0. "Python"[0] is the first character: "P".

13. What is the output of: print(type([]))?

  • A. <class "list"> ✓
  • B. <class "array">
  • C. <class "tuple">
  • D. <class "dict">

💡 An empty [] is a list in Python. type([]) returns <class "list">.

14. Which method adds an item to the end of a list?

  • A. insert()
  • B. add()
  • C. push()
  • D. append() ✓

💡 list.append(item) adds an item to the end of the list.

15. What does "try-except" do in Python?

  • A. Creates a loop
  • B. Defines a function
  • C. Handles exceptions/errors gracefully ✓
  • D. Imports a module

💡 try-except catches and handles errors so the program does not crash when an exception occurs.

More Programming Quizzes

View all Programming quizzes →