Python Week 4 Quiz Answers

  Python Week 4 Quiz Answers

Q1. Naming convention of a module of a python file is ?

·       All names should be lower case.

·       Underscore can be used.

·       Should be short

·       All of the above.

Ans- All of the above

Reasons: 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 (using python 3.X version):

def print_hello():

print ("Hello")


Now consider the following interaction on Python console, assuming

is in the current directory where the console is invoked:


>>> import hello

>>> hello.print_hello()

What will be the output of the code ?

Ans- "Hello" will be printed (without quotes)

Reason: Import is used in code it is used to import 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 website"):



     def display(self):

         return 0


print( obj.display() )

Ans- 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=''):



    def display(self):




Ans- 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- Creating an instance of class

Reason: instantiation means creating an instance or object oriented program. So 2nd option is correct.

Post a Comment