181. What is the output of print(__name__) when run directly?
- a) __main__
- b) main
- c) None
- d) Error
__name__ is '__main__' when a script is executed directly.
Test your knowledge of Python with these interactive multiple-choice questions.
181. What is the output of print(__name__) when run directly?
__name__ is '__main__' when a script is executed directly.
182. Which method is called when an object is created?
__init__ initializes new object instances.
183. What does print(hasattr(str, 'upper')) output?
hasattr() checks if an attribute exists (str has upper() method).
184. Which method is called when using with statement?
__enter__ at start of with block.
185. What is the output of print(isinstance(True, int))?
bool is a subclass of int in Python.
186. Which module is used for working with dates?
datetime module provides date/time handling.
187. What is the output of print(issubclass(bool, int))?
bool inherits from int in Python.
188. Which method is called when printing an object?
__str__ provides the informal string representation.
189. What does print(dir([])) output?
dir() returns an object's attributes/methods.
190. Which module is used for file system operations?
os module provides filesystem operations.
191. What is the output of print(help(list.append))?
help() displays documentation for Python objects.
192. Which module is used for command-line arguments?
sys.argv contains command-line arguments.
193. What does print(vars()) output?
vars() returns the local namespace dictionary.
194. Which method is called when accessing an attribute?
__getattribute__ is called for all attribute access.
195. What is the output of print(callable(len))?
len is a built-in function (callable).
196. Which module is used for mathematical operations?
math module provides math functions.
197. What does print(globals()) output?
globals() returns the global namespace dictionary.
198. Which method is called when deleting an attribute?
__delattr__ is called on attribute deletion.
199. What is the output of print('Hello'.__class__)?
__class__ returns an object's class.
200. Which module is used for JSON operations?
json module is Python's built-in JSON processor.