Python - MCQ Questions and Answers

Test your knowledge of Python with these interactive multiple-choice questions.

« First 7 8 9 10 Last »
« Previous Page Next Page »

181. What is the output of print(__name__) when run directly?

  • a) __main__
  • b) main
  • c) None
  • d) Error
Answer: A - __name__ is '__main__' when a script is executed directly.

182. Which method is called when an object is created?

  • a) __init__
  • b) __new__
  • c) __create__
  • d) __call__
Answer: A - __init__ initializes new object instances.

183. What does print(hasattr(str, 'upper')) output?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - hasattr() checks if an attribute exists (str has upper() method).

184. Which method is called when using with statement?

  • a) __enter__
  • b) __start__
  • c) __open__
  • d) __begin__
Answer: A - Context managers use __enter__ at start of with block.

185. What is the output of print(isinstance(True, int))?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - bool is a subclass of int in Python.

186. Which module is used for working with dates?

  • a) datetime
  • b) time
  • c) calendar
  • d) date
Answer: A - The datetime module provides date/time handling.

187. What is the output of print(issubclass(bool, int))?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - bool inherits from int in Python.

188. Which method is called when printing an object?

  • a) __str__
  • b) __repr__
  • c) __print__
  • d) __display__
Answer: A - __str__ provides the informal string representation.

189. What does print(dir([])) output?

  • a) List of list attributes/methods
  • b) Directory contents
  • c) []
  • d) Error
Answer: A - dir() returns an object's attributes/methods.

190. Which module is used for file system operations?

  • a) os
  • b) sys
  • c) path
  • d) files
Answer: A - The os module provides filesystem operations.

191. What is the output of print(help(list.append))?

  • a) Help text for append method
  • b) None
  • c] Error
  • d) True
Answer: A - help() displays documentation for Python objects.

192. Which module is used for command-line arguments?

  • a) sys
  • b) os
  • c) argparse
  • d) input
Answer: A - sys.argv contains command-line arguments.

193. What does print(vars()) output?

  • a) Current local symbol table
  • b) Global variables
  • c) Built-in functions
  • d) Error
Answer: A - vars() returns the local namespace dictionary.

194. Which method is called when accessing an attribute?

  • a) __getattribute__
  • b) __getattr__
  • c) __access__
  • d) __attribute__
Answer: A - __getattribute__ is called for all attribute access.

195. What is the output of print(callable(len))?

  • a) True
  • b) False
  • c) None
  • d) Error
Answer: A - len is a built-in function (callable).

196. Which module is used for mathematical operations?

  • a) math
  • b) numpy
  • c) calculate
  • d) arithmetic
Answer: A - The math module provides math functions.

197. What does print(globals()) output?

  • a) Current global symbol table
  • b] Local variables
  • c) Built-in names
  • d) Error
Answer: A - globals() returns the global namespace dictionary.

198. Which method is called when deleting an attribute?

  • a) __delattr__
  • b) __delete__
  • c) __remove__
  • d) __del__
Answer: A - __delattr__ is called on attribute deletion.

199. What is the output of print('Hello'.__class__)?

  • a) <class 'str'>
  • b) 'Hello'
  • c) <class 'object'>
  • d) Error
Answer: A - __class__ returns an object's class.

200. Which module is used for JSON operations?

  • a) json
  • b) simplejson
  • c) pickle
  • d) marshal
Answer: A - The json module is Python's built-in JSON processor.
« First 7 8 9 10 Last »
« Previous Page Next Page »

Learn Computer Skills with PCBooks

Master computer skills with PCBooks! Explore interactive tutorials, MCQ tests, and online exams for programming, web development, and IT fundamentals. Perfect for beginners and advanced learners.

Online MCQ Tests for Programming

Practice programming MCQ questions and improve your coding skills with our online quizzes. Whether you're learning Python, Java, or C programming, PCBooks has you covered.

Free Web Development Tutorials

Learn HTML, CSS, and JavaScript with our free web development tutorials. Test your knowledge with interactive quizzes and online exams.