Python Interview questions - faa
(Python version 3.9 or later version)
Which of the following python statements will not be ignored by python interpreter, but the interpreter does nothing at run time as the intended use of the statement is to act as a stand-in or placeholder?
def f9():
'''This is a docstring'''
# This is a comment
pass
yield
|
'''This is a docstring'''
# This is a comment
pass
yield
|
Explanation
Python interpreter upon executing pass statement, does nothing at run time as the intended use of the statement is to act as a stand-in or placeholder. The pass keyword is an entire statement by itself. It simply does nothing: it’s discarded during the byte-compile phase. It is generally used as a place-holder for future code.
pass is an ideal future code filler for class/function definitions as their bodies cannot be empty. Similarly, control statements and loops cannot have empty blocks, so pass can be a good place-holder.
|