PYTHON QUIZ 7(Solution with the answer)
· All names should be lower case.
· Underscore can be used.
· Should be short
· All of the above.
Ans(d)- All of the above
Reason: Naming convention of a module should have short, all-lowercase names. Underscores can be used in the module name if it improves readability.
Q2. The following code is saved in a file hello.py (using python 3.X version):
def print_hello():
print ("Hello")
Now consider the following interaction on Python console, assuming hello.py
is in the current directory where the console is invoked:
>>> import hello
>>> hello.print_hello()
What will be the output of the code ?
Ans(b)- "Hello" will be printed (without quotes)
Reason: Import is used in code it is used to import hello.py program with our environment. Then hello.print_hello() execute the print_hello() function and print Hello as output so 2nd option is correct.
Q3. What is the output of the following python code?
class hello:
def __init__(self,a="Visit Prutor.ai website"):
self.a=a
def display(self):
return 0
obj=hello()
print( obj.display() )
Ans(b)- 0
Reason: Constructor set the value of variable as a given string then print(obj.display()) call and display method execute and return 0. So 0 will be printed as output.
Q4. What is the output of the following python code?
class test:
def __init__(self,x=''):
self.x=x
def display(self):
print(self.x)
obj=test()
obj.display()
Ans(a)- Executes normally and doesn’t display anything
Reason: obj=test() will create an object and the constructor _int_ initialise x to blank string, after display method called in next line and it prints the blank string as output.
Q5. What does Instantiation mean in terms of Object Oriented Programming?
· Deleting an instance of class
· Creating an instance of class
· Copying an instance of class
· Modifying an instance of class
Ans(b)- Creating an instance of class
Reason: instantiation means creating an instance or object oriented program. So 2nd option is correct.
Hope you guys have liked this again and hey stay connected in this blog for more Information, Stay Safe, See you soon.
Till then Jai Hind and Vande Mataram 😇.
Comments
Post a Comment