This Python Quiz contains 20 multiple-choice questions with answers and short explanations. It covers Python syntax, variables, operators, strings, collections, loops, functions, exceptions, classes, and modules. A simple Python quiz program with score calculation is included after the answer key.

How to Use This Python Quiz for Beginners

  • Select one answer for each Python MCQ.
  • Record your choices before checking the answer key.
  • Give yourself one point for every correct answer.
  • Run code-based questions in Python when you want to verify the result.

Python Syntax, Variables, and Operators Quiz

1. Which extension is normally used for a Python source file?

  1. .java
  2. .py
  3. .html
  4. .cpp

2. Which function displays a value in the console?

  1. echo()
  2. show()
  3. print()
  4. write()

3. Which character starts a single-line Python comment?

  1. //
  2. #
  3. /*
  4. --

4. Which statement assigns the integer 10 to count?

  1. int count = 10
  2. count := 10
  3. count = 10
  4. let count = 10

5. What is the result of 17 // 5?

  1. 2
  2. 3
  3. 3.4
  4. 4

6. Which operator returns the remainder after division?

  1. /
  2. //
  3. %
  4. **

Python Strings and Collections Quiz

7. What is the output of this Python code?

</>
Copy
text = "Python"
print(text[0])
  1. P
  2. y
  3. n
  4. An error

8. What is the value of "Python"[1:4]?

  1. Pyt
  2. yth
  3. ytho
  4. tho

9. Which Python collection is ordered, mutable, and allows duplicates?

  1. List
  2. Tuple
  3. Set
  4. Frozen set

10. Which method adds one item to the end of a list?

  1. add()
  2. push()
  3. append()
  4. extend_one()

11. Which expression creates a one-item tuple?

  1. (5)
  2. [5]
  3. (5,)
  4. {5}

12. Which syntax creates a dictionary?

  1. {"name": "Maya", "age": 20}
  2. ["name", "Maya"]
  3. ("name", "Maya")
  4. {"name", "Maya"}

Python Loops and Functions Quiz

13. What values are generated by range(3)?

  1. 1, 2, 3
  2. 0, 1, 2
  3. 0, 1, 2, 3
  4. 3 only

14. Which keyword skips the rest of the current loop iteration?

  1. break
  2. continue
  3. pass
  4. return

15. Which keyword exits the nearest loop immediately?

  1. stop
  2. exit
  3. break
  4. continue

16. Which keyword defines a Python function?

  1. function
  2. func
  3. def
  4. define

17. What does a function return when it ends without a return statement?

  1. 0
  2. An empty string
  3. False
  4. None

Python Exceptions, Classes, and Modules Quiz

18. Which block handles a matching exception raised in a try block?

  1. catch
  2. except
  3. error
  4. handle

19. What is the conventional first parameter of an instance method?

  1. this
  2. object
  3. self
  4. instance

20. Which statement imports the math module?

  1. include math
  2. using math
  3. import math
  4. require math

Python Quiz Answers with Explanations

QuestionAnswerExplanation
12Python source files normally use the .py extension.
23print() sends a string representation of values to standard output.
32A hash character begins a comment that continues to the end of the line.
43Python assigns a value with the equals operator and does not require a declared variable type.
52Floor division returns the quotient rounded down; 17 divided by 5 produces 3.
63The modulo operator returns the remainder after division.
71String indexes begin at zero, so index 0 selects P.
82The slice starts at index 1 and stops before index 4, producing yth.
91A list is ordered, mutable, and can contain duplicate values.
103append() adds one object to the end of a list.
113The trailing comma is what makes (5,) a one-item tuple.
121A dictionary uses key-value pairs separated by colons inside braces.
132range(3) begins at zero and excludes the stop value 3.
142continue moves execution to the next loop iteration.
153break terminates the nearest enclosing loop.
163A function definition starts with the def keyword.
174A function that finishes without another return value returns None.
182An except block handles a matching exception raised by the protected code.
193self is the conventional name for the current object passed to an instance method.
203import math loads the module and binds it to the name math.

Python Quiz Score Guide

ScoreResultSuggested review
17–20Strong understanding of Python fundamentalsContinue with comprehensions, files, testing, iterators, and small projects.
13–16Good beginner-level foundationReview missed questions and practise writing functions that use collections.
8–12Developing foundationRevisit indexing, operators, loops, functions, and dictionaries.
0–7More Python basics practice is neededStart with variables, data types, strings, lists, conditions, and simple loops.

Simple Python Quiz Code with Score

This example stores questions in a list of dictionaries, accepts one answer per question, and calculates the final score. The call to strip().lower() makes uppercase answers and surrounding spaces acceptable.

</>
Copy
questions = [
    {
        "question": "Which keyword defines a function?",
        "options": ["A. func", "B. define", "C. def", "D. function"],
        "answer": "c",
    },
    {
        "question": "Which collection stores key-value pairs?",
        "options": ["A. List", "B. Dictionary", "C. Tuple", "D. Set"],
        "answer": "b",
    },
    {
        "question": "What does len('Python') return?",
        "options": ["A. 5", "B. 6", "C. 7", "D. Error"],
        "answer": "b",
    },
]

score = 0

for number, item in enumerate(questions, start=1):
    print(f"\n{number}. {item['question']}")

    for option in item["options"]:
        print(option)

    choice = input("Your answer: ").strip().lower()

    if choice == item["answer"]:
        print("Correct")
        score += 1
    else:
        print(f"Incorrect. Correct answer: {item['answer'].upper()}")

print(f"\nFinal score: {score}/{len(questions)}")

Example output for three correct answers:

1. Which keyword defines a function?
A. func
B. define
C. def
D. function
Your answer: c
Correct

2. Which collection stores key-value pairs?
A. List
B. Dictionary
C. Tuple
D. Set
Your answer: b
Correct

3. What does len('Python') return?
A. 5
B. 6
C. 7
D. Error
Your answer: b
Correct

Final score: 3/3

Python Quiz Topics to Review

  • Python data types: integers, floats, strings, Boolean values, lists, tuples, sets, dictionaries, and None.
  • Sequence behavior: zero-based indexing, negative indexing, slicing, membership, and len().
  • Control flow: if, elif, else, for, while, break, and continue.
  • Functions: parameters, return values, default arguments, *args, and **kwargs.
  • Exceptions and classes: try, except, class definitions, instance methods, and self.

Python Quiz FAQs

Is this Python quiz suitable for beginners?

Yes. It starts with syntax and operators, then covers strings, collections, loops, functions, exceptions, classes, and imports. The explanations can be used for revision after the quiz.

Why does range(3) produce 0, 1, and 2?

The stop value given to range() is excluded. This means range(3) starts at zero by default and ends before 3.

What is the difference between a Python list and a tuple?

A list is mutable, so its items can be changed after creation. A tuple is immutable. Lists use square brackets, while tuples are commonly written with comma-separated values inside parentheses.

How can I add more questions to the Python quiz game?

Add another dictionary to the questions list with a question, four displayed options, and the correct answer letter. The loop automatically includes the new entry in the score.

How should I practise after completing the Python quiz?

Rewrite the code examples, predict their output before running them, and build short programs that combine conditions, loops, functions, and collections. Practical exercises reveal gaps that multiple-choice questions may not show.

Python Quiz Editorial QA Checklist

  • Run every Python code question and confirm that the stated output is correct.
  • Verify that every Python MCQ has exactly one unambiguous answer.
  • Check indexes, slice endpoints, floor division, modulo, and range() boundaries.
  • Confirm that list, tuple, set, and dictionary descriptions distinguish their behavior correctly.
  • Recheck answer-key numbering after adding, removing, or rearranging questions.
  • Test the quiz program with correct, incorrect, uppercase, lowercase, and space-padded input.