💻
Programming Medium

Python Programming Fundamentals

Play this programming quiz on Python fundamentals — 15 medium-level questions and answers.

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. Which symbol is used for comments in Python?

  • A. //
  • B. # ✓
  • C. --
  • D. /* */

💡 The '#' symbol is used to write single-line comments in Python.

2. What does the 'try/except' block do in Python?

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

💡 The 'try/except' block allows a program to handle errors gracefully without crashing.

3. What does len() do in Python?

  • A. Returns the length of an object ✓
  • B. Deletes an object
  • C. Creates a loop
  • D. Converts data types

💡 The len() function returns the number of items in an object, such as a string or list.

4. What data type is used to store True or False in Python?

  • A. int
  • B. bool ✓
  • C. str
  • D. float

💡 The 'bool' data type stores Boolean values, True or False, in Python.

5. What does 'None' represent in Python?

  • A. The absence of a value ✓
  • B. Zero
  • C. An error
  • D. A Boolean false

💡 'None' is a special value in Python representing the absence of a value or a null value.

6. What is a Python dictionary used for?

  • A. Storing key-value pairs ✓
  • B. Storing only numbers
  • C. Storing only text
  • D. Creating loops

💡 A Python dictionary stores data as key-value pairs, allowing fast lookup by key.

7. What is the correct way to create a list in Python?

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

💡 Lists in Python are created using square brackets, like [1, 2, 3].

8. What is 'self' used for in Python class methods?

  • A. To refer to the instance of the class ✓
  • B. To end a function
  • C. To import a module
  • D. To create a loop

💡 'self' refers to the current instance of a class and is used to access its attributes and methods.

9. What keyword is used to create a class in Python?

  • A. class ✓
  • B. def
  • C. object
  • D. struct

💡 The 'class' keyword is used to define a new class in Python.

10. What does 'import' do in Python?

  • A. Brings in external modules or libraries ✓
  • B. Deletes a variable
  • C. Ends the program
  • D. Creates a loop

💡 The 'import' statement brings in code from external modules or libraries for use in a program.

11. Which keyword is used to define a function in Python?

  • A. func
  • B. def ✓
  • C. function
  • D. define

💡 The 'def' keyword is used to define a function in Python.

12. What is the correct file extension for Python files?

  • A. .py ✓
  • B. .python
  • C. .pt
  • D. .pyt

💡 Python files are saved with the .py file extension.

13. What does 'for i in range(5):' do?

  • A. Loops 5 times ✓
  • B. Loops indefinitely
  • C. Loops once
  • D. Causes an error

💡 range(5) generates numbers 0 through 4, so this loop executes 5 times.

14. What is the output of print(2 + 3) in Python?

  • A. 23
  • B. 5 ✓
  • C. 2+3
  • D. Error

💡 Python evaluates 2 + 3 as arithmetic addition, printing the result, 5.

15. Which method adds an item to the end of a list in Python?

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

💡 The append() method adds a single item to the end of a Python list.

More Programming Quizzes

View all Programming quizzes →