Q. Consider a module 'simple' given below:


# module simple.py
"""Greets or scolds on call"""

def greet():
    """Greet anyone you like :-)"""
    print ("Helloz")

def scold():
    """Use me for scolding, but scolding is not good :-("""
    print("Get lost")

count = 10
print("greeting or scolding - is it simple ?")

Another program 'test.py' imports this module. The code inside test.py is:-


#test.py
import simple
print (simple.count)

What would be the output produced, if we run the program test.py? Justify your answer.


Answer :-

The output produced would be:

greeting or scolding - is it simple ?
10

The reason being, import module's main block is executed upon import, so its import statement causes it to print :

greeting or scolding - is it simple ?

And print(simple.count) statement causes output's next line, i.e.,

10

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post