Q. Consider the code of module welcome.py given below
#welcome.py
"""
welcome
~~~~~~~
This module contains the greeting message 'msg' and greeting function 'greet()'.
"""
msg = 'Hello' # Global Variable
def greet(name): # Function
print('{}, {}'.format(msg, name))
Now carefully go through the code statements given below and figure out what will be their output. Every successive statement should assume that previous code statements hold i.e., part (a) holds for (b); parts (a), (b) hold for (c) and so on.
(a)
>>> import welcome
(b)
>>> welcome.greet('Parth')
>>> print(welcome.msg)
(c)
>>> welcome.__doc___
>>> welcome.__name__
(d)
>>> help (welcome)
(e)
>>> import welcome as wel
>>> wel.greet('Radha')
Answer :-
Note :- At first you have to create ‘welcome.py’ file.
>>> import welcome
>>> welcome.greet('Parth')
Hello, Parth
>>> print (welcome.msg)
Hello
Hello
>>> welcome.__doc__
"\nwelcome\n~~~~~~~\nThis module contains the greeting message 'msg' and greeting function 'greet()'.\n"
"\nwelcome\n~~~~~~~\nThis module contains the greeting message 'msg' and greeting function 'greet()'.\n"
>>> welcome.__name__
' welcome'
>>> help(welcome)
Help on module welcome:
NAME
welcome
DESCRIPTION
welcome
~~~~~~~
This module contains the greeting message 'msg' and greeting function 'greet()'.
FUNCTIONS
greet(name)
DATA
msg = 'Hello'
FILE
c:\users\p w\desktop\ welcome.py
>>> import welcome as wel
>>> wel.greet('Radha')
Hello, Radha
>>>
>>> wel.greet('Radha')
Hello, Radha
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )