Python Quiz 8


 Q:1. In Python, a class is created by _________ keyword, and to create ________ of the class, we will have to use constructor of class.

Answer :   2.      class, object


Q:2. What will be the output of the following python code?

class Roll:

        def __init__(self,id):

                self.id=id

                id=231

                return id

val = Roll(321)

print(val.id)

Answer :   1.     TypeError


Q:3. What will be the output of the following python code?

class x:

        def __init__(self):

                self.a=10

                self._b=20

                self.b=20

        def getB(self):

                return self.b

x=X()

x._b=60

print(x.getB())

Answer :  1.      20


Q:4. Private method in python starts with ________  while protected methods starts with ________.

Answer :   2      double underscore, single underscore


Q:5. What will be the output of the following code. Code is saved in a file named 'code.py' :

f=open('file.txt')

f.readlines()

print(f.name)

print( f.closed)

f.close()

print( f.closed )

Answer :   1.      Error in code







No comments:

Post a Comment