In Python 3, what is the value of 7 / 2?
Correct answer C. 3.5
Topic / 88 questions
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.
Correct answer C. 3.5
Correct answer D. Always, whether or not an exception occurred in the try block
Correct answer C. 'a'
Correct answer C. FileExistsError is raised
Correct answer D. The contents are erased because the file is truncated
Correct answer A. The file is closed automatically when the block ends, even if an exception occurs
Correct answer D. __enter__ and __exit__
Correct answer B. The instance on which the method was called
Correct answer C. It initialises a newly created instance, typically setting its attributes
Correct answer B. A static method receives no implicit first argument, while a class method receives the class as cls
Correct answer D. _Account__balance
Correct answer B. C3 linearisation
Correct answer B. The method can be accessed like an attribute, without parentheses
Correct answer D. StopIteration
Correct answer B. Using the yield keyword in its body
Correct answer D. Any integer from 1 to 6, including both 1 and 6
Correct answer D. deque
Correct answer B. 3
Correct answer A. 1, 2, 3
Correct answer A. __len__
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.
Pakistan
India
Bangladesh
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.
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