Python Basics Quiz: 60 MCQs with Answers, Timer and Mark Sheet
Test your Python fundamentals with 60 multiple-choice questions on variables, data types, strings, lists, dictionaries, loops, functions and errors. Pick 10, 20 or 30 questions, beat the timer and get a printable mark sheet with explanations.

Python Basics Quiz
60 questions · 8 topics · timer · instant explanations · printable mark sheet.
- Questions60 in the bank, 10–30 per attempt
- Levels20 easy · 24 medium · 16 hard
- TimeAbout 5–20 minutes
- PriceFree, no login needed
- Made byDr. Aammar Tufail, Codanics
- Updated18 November 2026
In short: the Python Basics Quiz is a free online multiple-choice quiz by Codanics with 60 questions on variables and data types; operators and expressions; strings and f-strings; lists, tuples, sets, dicts; conditionals and loops; functions and scope; errors and exceptions; and files, modules and OOP. You choose the number of questions and the difficulty, answer against a timer, see an explanation after every answer and finish with a printable mark sheet.
What the Python Basics Quiz covers
Python is the most popular first language for data science and AI, and its basics decide how fast you learn everything that follows. This quiz checks whether you really understand how Python behaves, not just whether you remember the syntax.
Many questions show a short piece of code and ask what it prints, because predicting output is the fastest way to find gaps in your understanding. Every answer comes with a short explanation, so you learn something from every mistake.
- Variables and data types 7 questions
- Operators and expressions 7 questions
- Strings and f-strings 8 questions
- Lists, tuples, sets, dicts 8 questions
- Conditionals and loops 7 questions
- Functions and scope 8 questions
- Errors and exceptions 8 questions
- Files, modules and OOP 7 questions
Who it is for: Beginners who have just started Python, students in their first programming course and anyone preparing for a Python interview or exam.
How the quiz works
- Type your name if you want it printed on the mark sheet (optional; it never leaves your browser).
- Choose 10, 20 or 30 questions, a difficulty (Easy, Mixed or Hard) and the timer: Standard, Relaxed or none.
- Answer each question before the timer runs out. Press A–D or 1–4 on a keyboard, or tap an option on your phone.
- Read the explanation after every answer, then press Next.
- At the end, get your score, grade, topic-wise breakdown and a full answer review. Print it or save it as a PDF.
- Retake the quiz for a fresh random set, or practise only the topics you found hard.
Free video lessons from Codanics
Score lower than you hoped? These free lessons from the Codanics YouTube channel cover the same topics, explained step by step.
Free on the Codanics YouTube channel, taught in Urdu/Hindi.
Sample questions with answers
Here are 9 questions from the bank, with answers and explanations. The quiz above draws from all 60.
1. What does the following code print? (print(type(3.0)))
print(type(3.0))- <class 'int'>
- <class 'float'>
- <class 'str'>
- <class 'double'>
Answer: B. <class 'float'>
Any number written with a decimal point is a float in Python, even if the fractional part is zero. Python has no separate 'double' type.
2. What is the value of 7 // 2 in Python?
- 3.5
- 4
- 3
- 1
Answer: C. 3
// is floor division: it divides and rounds down to the nearest whole number, so 7 // 2 is 3. Plain / would give 3.5.
3. What does the following code print? (s = "Python")
s = "Python"
print(s[0], s[-1])- P n
- P o
- y n
- n P
Answer: A. P n
Index 0 is the first character and index -1 is the last one. Negative indices count backwards from the end of the string.
4. What does the following code print? (name = "Ali")
name = "Ali"
age = 21
print(f"{name} is {age + 1}")- Ali is 21 + 1
- {name} is {age + 1}
- Ali is 211
- Ali is 22
Answer: D. Ali is 22
Inside an f-string, anything in curly braces is evaluated as a Python expression, so {age + 1} becomes 22.
5. What does the following code print? (a = [1, 2, 3])
a = [1, 2, 3]
b = a
b.append(4)
print(a)- [1, 2, 3]
- [4]
- [1, 2, 3, [4]]
- [1, 2, 3, 4]
Answer: D. [1, 2, 3, 4]
b = a does not copy the list; both names refer to the same list object. Changing it through b is visible through a. Use a.copy() to get an independent list.
6. What does the following code print? (for i in range(3):)
for i in range(3):
print(i, end=" ")- 1 2 3
- 0 1 2
- 0 1 2 3
- 1 2
Answer: B. 0 1 2
range(3) produces 0, 1 and 2: it starts at 0 and stops before 3.
7. What does the following code print? (def greet(name, msg="Hello"):)
def greet(name, msg="Hello"):
return f"{msg}, {name}"
print(greet("Fatima"))- Fatima, Hello
- Hello, Fatima
- , Fatima
- TypeError: missing argument
Answer: B. Hello, Fatima
msg has a default value, so it is optional. Calling greet('Fatima') uses msg = 'Hello'.
8. Which exception does this code raise? (age = "5")
age = "5"
print(age + 5)- TypeError
- ValueError
- SyntaxError
- NameError
Answer: A. TypeError
Python will not automatically mix str and int with +. Convert first, e.g. int(age) + 5 or age + str(5).
9. What is the main advantage of opening a file with 'with open("data.txt") as f:'?
- The file is read faster
- The file is opened in write mode
- The file is locked for other users
- The file is closed automatically
Answer: D. The file is closed automatically
The with statement is a context manager: it closes the file when the block ends, even if an exception happens inside it.
Free guides and blogs to study
Free tools for your studies and research
Codanics also has 160+ free online tools for students and researchers: statistics calculators, meta-analysis, PDF and writing tools. They run in your browser, with no login.
Frequently asked questions
Is the Python Basics Quiz free?
Yes. The Python Basics Quiz is completely free, with no sign-up, no login and no limit on attempts.
How many questions are in the Python Basics Quiz?
The question bank has 60 multiple-choice questions (20 easy, 24 medium and 16 hard) across 8 topics. Each attempt draws 10, 20 or 30 of them at random, so every attempt is different.
How does the timer work?
Each question has its own countdown: about 25 seconds for easy, 40 for medium and 55 for hard questions, plus 15 seconds when there is code to read. Choose Relaxed to double the time or switch the timer off to study at your own pace. Unanswered questions count as skipped.
Can I get a certificate or mark sheet?
Yes. When you finish, you get a mark sheet with your name, score, grade, time, topic-wise performance and every answer explained. Use Print or save as PDF to keep it. It is a self-assessment result, not an official certificate.
Are the answers and explanations correct?
Every question was written and reviewed for one clearly correct answer, and code questions were checked by running the code. If you think an answer is wrong, tell us on the Codanics WhatsApp channel or in the YouTube comments and we will fix it.
Is this Python quiz good for complete beginners?
Yes. Choose Easy and 10 questions for a gentle start. Mixed and Hard add code-reading questions on loops, functions and errors that are common in exams and interviews.
Which Python version does the quiz use?
Python 3. All code questions were checked with a recent Python 3 release, so the outputs match what you see in VS Code, Jupyter or Google Colab.
Is my data stored anywhere?
No. The quiz runs entirely in your browser. Your name, answers and score are not uploaded. Your best score and settings are remembered only in this browser so you can track your progress.
More free quizzes
See all Codanics quizzes → · Courses · Free tools · Blog



