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?
.java.py.html.cpp
2. Which function displays a value in the console?
echo()show()print()write()
3. Which character starts a single-line Python comment?
//#/*--
4. Which statement assigns the integer 10 to count?
int count = 10count := 10count = 10let count = 10
5. What is the result of 17 // 5?
233.44
6. Which operator returns the remainder after division?
///%**
Python Strings and Collections Quiz
7. What is the output of this Python code?
text = "Python"
print(text[0])
Pyn- An error
8. What is the value of "Python"[1:4]?
Pytythythotho
9. Which Python collection is ordered, mutable, and allows duplicates?
- List
- Tuple
- Set
- Frozen set
10. Which method adds one item to the end of a list?
add()push()append()extend_one()
11. Which expression creates a one-item tuple?
(5)[5](5,){5}
12. Which syntax creates a dictionary?
{"name": "Maya", "age": 20}["name", "Maya"]("name", "Maya"){"name", "Maya"}
Python Loops and Functions Quiz
13. What values are generated by range(3)?
1, 2, 30, 1, 20, 1, 2, 33only
14. Which keyword skips the rest of the current loop iteration?
breakcontinuepassreturn
15. Which keyword exits the nearest loop immediately?
stopexitbreakcontinue
16. Which keyword defines a Python function?
functionfuncdefdefine
17. What does a function return when it ends without a return statement?
0- An empty string
FalseNone
Python Exceptions, Classes, and Modules Quiz
18. Which block handles a matching exception raised in a try block?
catchexcepterrorhandle
19. What is the conventional first parameter of an instance method?
thisobjectselfinstance
20. Which statement imports the math module?
include mathusing mathimport mathrequire math
Python Quiz Answers with Explanations
| Question | Answer | Explanation |
|---|---|---|
| 1 | 2 | Python source files normally use the .py extension. |
| 2 | 3 | print() sends a string representation of values to standard output. |
| 3 | 2 | A hash character begins a comment that continues to the end of the line. |
| 4 | 3 | Python assigns a value with the equals operator and does not require a declared variable type. |
| 5 | 2 | Floor division returns the quotient rounded down; 17 divided by 5 produces 3. |
| 6 | 3 | The modulo operator returns the remainder after division. |
| 7 | 1 | String indexes begin at zero, so index 0 selects P. |
| 8 | 2 | The slice starts at index 1 and stops before index 4, producing yth. |
| 9 | 1 | A list is ordered, mutable, and can contain duplicate values. |
| 10 | 3 | append() adds one object to the end of a list. |
| 11 | 3 | The trailing comma is what makes (5,) a one-item tuple. |
| 12 | 1 | A dictionary uses key-value pairs separated by colons inside braces. |
| 13 | 2 | range(3) begins at zero and excludes the stop value 3. |
| 14 | 2 | continue moves execution to the next loop iteration. |
| 15 | 3 | break terminates the nearest enclosing loop. |
| 16 | 3 | A function definition starts with the def keyword. |
| 17 | 4 | A function that finishes without another return value returns None. |
| 18 | 2 | An except block handles a matching exception raised by the protected code. |
| 19 | 3 | self is the conventional name for the current object passed to an instance method. |
| 20 | 3 | import math loads the module and binds it to the name math. |
Python Quiz Score Guide
| Score | Result | Suggested review |
|---|---|---|
| 17–20 | Strong understanding of Python fundamentals | Continue with comprehensions, files, testing, iterators, and small projects. |
| 13–16 | Good beginner-level foundation | Review missed questions and practise writing functions that use collections. |
| 8–12 | Developing foundation | Revisit indexing, operators, loops, functions, and dictionaries. |
| 0–7 | More Python basics practice is needed | Start 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.
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, andcontinue. - Functions: parameters, return values, default arguments,
*args, and**kwargs. - Exceptions and classes:
try,except, class definitions, instance methods, andself.
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.
TutorialKart.com