Topic / 88 questions

Python MCQs

Python MCQs test your understanding of the Python 3 language, from basic syntax and data types to functions, object-oriented programming, exceptions and the standard library. Many questions show a short code snippet and ask for its exact output, which is the format used in campus placements, IT job tests and programming interviews. Every answer comes with an explanation of the rule behind it.

Question 02 Python

When does the finally clause of a try statement execute?

Correct answer D. Always, whether or not an exception occurred in the try block

Open question
Advertisement
Question 09 Python

What is the role of the __init__ method in a Python class?

Correct answer C. It initialises a newly created instance, typically setting its attributes

Open question
Advertisement
Question 10 Python

How does a @staticmethod differ from a @classmethod in Python?

Correct answer B. A static method receives no implicit first argument, while a class method receives the class as cls

Open question
Question 13 Python

What is the effect of decorating a method with @property?

Correct answer B. The method can be accessed like an attribute, without parentheses

Open question
Advertisement
Question 16 Python

Which values can random.randint(1, 6) return?

Correct answer D. Any integer from 1 to 6, including both 1 and 6

Open question

About Python MCQs

The set starts with fundamentals: identifiers and keywords, indentation, comments, dynamic typing and the core built-in types. It then covers operators and precedence, including floor division, the modulus operator with negative numbers, identity versus equality and short-circuit evaluation.

Further questions look at strings and slicing, lists, tuples, sets and dictionaries, comprehensions, loops with else clauses, and the match statement added in Python 3.10. Functions are covered in depth: default arguments, the mutable default pitfall, *args and **kwargs, the LEGB scope rule, global and nonlocal, lambda and recursion.

The final group covers modules and packages, exceptions and the exception hierarchy, file modes and the with statement, classes, inheritance, name mangling, properties, static and class methods, iterators and generators, and useful standard-library tools such as collections and itertools. Code questions were run on Python 3 to confirm the answers.

Key facts to remember

  • Python was created by Guido van Rossum and first released in 1991.
  • Python 2 reached end of life on 1 January 2020.
  • Dictionaries preserve insertion order as a language guarantee from Python 3.7.
  • The / operator always returns a float in Python 3; // is floor division.
  • PEP 8 recommends 4 spaces per indentation level and lines of at most 79 characters.

Exams that include Python MCQs

Pakistan

  • NTS
  • PPSC Computer Science Lecturer
  • FPSC IT posts
  • University entry tests

India

  • Campus placements
  • GATE CS (programming basics)
  • UGC NET Computer Science
  • IT company aptitude tests

Bangladesh

  • BCS (technical cadre)
  • Bank IT officer tests
  • Government programmer posts

How to prepare for Python MCQs

  1. For output questions, trace the code line by line and write down each variable's value.
  2. Remember which types are mutable (list, dict, set) and which are immutable (int, str, tuple).
  3. Watch for default arguments that are lists or dicts: they are created once, not on every call.
  4. Learn the difference between / and //, and between is and ==.

Frequently asked questions

Are these Python MCQs based on Python 2 or Python 3?

All questions use Python 3 behaviour, the version taught and used today. Python 2 reached end of life on 1 January 2020, and differences such as print being a function and / returning a float are explained where they matter.

Which Python topics are asked most in job tests?

Recruitment tests and placement papers most often ask about data types, string slicing, list and dictionary methods, operator precedence, functions and scope, exceptions, and simple code-output questions. Object-oriented topics such as inheritance and special methods are common in interviews.

Last reviewed October 2026