Python MCQ questions with answers
Pick a topic, choose an answer and see why it is right, with code you can run in the editor.
Quick test
Basics
- Python basicsVariables, data types, type conversion and print: pick an answer to see why it is right.
- OperatorsArithmetic, comparison, logical and identity operators, with the traps exams like to set.
- StringsIndexing, slicing, methods and formatting: predict the output, then check.
- ConditionalsWhich branch runs, and why: if, elif, else, truthiness and match.
- Loopsfor, while, range, break and continue: count the passes before you check.
Lists, tuples, dictionaries and sets
- ListsSlicing, list methods, copies and aliases: the list questions exams ask most.
- TuplesImmutability, packing and unpacking, and the tuple that holds a list.
- DictionariesKeys, values and the methods that read and change them.
- SetsUnique values and set operations, with the questions that trip people up.
- ComprehensionsRead the comprehension, predict the list: conditions, nesting and generators.
Functions, errors, classes and files
- FunctionsArguments, defaults, scope and return values, including the classic traps.
- Lambda, map and filterlambda, map, filter, sorted keys and closures, one question at a time.
- Exceptionstry, except, else and finally: which block runs, and in what order.
- Classes and objectsClasses, objects, inheritance and special methods, with explanations.
- File handlingOpen modes, reading, writing and the with statement: the file questions CBSE asks.
Questions
Are the answers checked?
Yes. Every question with code is run in Python 3 before it is published, and the marked answer must be exactly what the code prints or the error it raises.
Do these questions cover the CBSE Class 11 and 12 syllabus?
They cover the Python topics the CBSE syllabus and most first-year programming courses teach: data types, operators, strings, conditions, loops, lists, tuples, dictionaries, functions, exceptions and file handling. Each topic page links the lesson that teaches it.
Can I see why an answer is right?
Every question has an explanation of the right answer and the tempting wrong one, and the code opens in the editor so you can change it and run it again.
For a question a day, try the daily Python puzzle; to write code that is checked by tests, the coding challenges.