Disclaimer for News Pustak

If you require any more information or you have any problems regarding copyright or have any questions about our site’s disclaimer, please feel free to contact us by email at newspustak24@gmail.com

Disclaimer for News Pustak

All the information on the website is published in good faith and for general information and educational purpose only. News Pustak does not make any warranties about the completeness, reliability, and accuracy of this information. Any action you take upon the information you find on this website is strictly at your own risk. We will not be liable for any losses and/or damage in connection with the use of our website.

Python Answers of 8th week – quiz

[1] A class definition in python begins with the keyword –
  • (a): def
  • (b): class
  • (c): self
  • (d): None of these
Answer: (b) class
[2] Which of the following statements is best suited for the declaration x = Point() in python where Point is defined as a class?
  • (a): x contains an int value.
  • (b): x contains an object of the Point type
  • (c): x contains a reference to a Point object.
  • (d): None of these
Answer: (c) x contains a reference to a Point object.
[3] What will be the output of the following python code?
class Roll:
def __init__(self, id):
self.id = id
id = 231
val = Roll(321)
print (val.id).
  • (a): Error
  • (b): 231
  • (c): 321
  • (d): None of these
Answer: (c) 321
[4] Special methods need to be explicitly called during object creation in python.
  • (a): True
  • (b): False
Answer: (b) False
[5] What will be the output of following python code?
class X:
def __init__(self):
self.a = 10
self._b = 20
def getB(self):
return self._b
x = X()
x._b = 60
print(x.getB())
  • (a): 20
  • (b): 60
  • (c): Error
  • (d): Program runs but does not print anything


Answer: (b) 60
[6] A class can inherit attributes and methods from another class, this another class is then called –
  • (a): subclass
  • (b): superclass
  • (c): childclass
  • (d): heirclass
Answer: (b) superclass
[7] Consider a scenario where vehicle, bike, car and bus are the classes in a python script. Which of the following class is most likely to be implemented as the superclass –
  • (a): bike
  • (b): vehicle
  • (c): car
  • (d): bus
Answer: (b) vehicle
[8] In python, every class is inherited from an object class.
  • (a): True
  • (b): False
Answer: (a) True
[9] What will be the output of following python code –
class Person:
def getInfo(self):
return “Person’s getInfo is called”
def printPerson(self):
print(self.getInfo())
class Staff(Person):
def getInfo(self):
return “Staff’s getInfo is called”
def main():
Person().printPerson()
Staff().printPerson()
main()
  • (a): Person’s getInfo is called
    Person’s getInfo is called
  • (b): Person’s getInfo is called
    Staff’s getInfo is called
  • (c): Staff’s getInfo is called
    Person’s getInfo is called
  • (d): Staff’s getInfo is called
    Staff’s getInfo is called
Answer: (b)
Person’s getInfo is called
Staff’s getInfo is called
[10] What will be the output of following python code –
class A:
def __init__(self, i = 0, j = 0):
self.i = i
self.j = j
def __str__(self):
return “some string”
def __eq__(self, other):
return self.i * self.j == other.i * other.j
def main():
x = A(4, 3)
y = A(6, 2)
print(x == y)
main()
  • (a): True
  • (b): False


Answer: (a) True
[11] In python, the name of a private method in a class begins with –
  • (a): _ (underscore)
  • (b): _ (double underscores)
  • (c): private keyword
  • (d): None of these
Answer: (b) _ (double underscores)
[12] In python, select the correct alternative about pass keyword –
  • (a): pass is used when a statement is required syntactically but no command/code is required to execute
  • (b): pass is a null operation
  • (c): pass is useful in places where code will eventually go, but has not been written yet
  • (d): All of the above
Answer: (d) All of the above
[13] In python, does the is instance method return a value of type Boolean?
  • (a): True
  • (b): False
Answer: (a) True
[14] In object oriented programming, encapsulation refers to bundling of data attributes and methods operating on them.
  • (a): True
  • (b): False


Answer: (a) True
[15] Information hiding in object oriented programming enables users of a class to –
  • (a): Must rely only on the interface, but not rely on internals.
  • (b): Depend on what is implemented, but not how it is implemented.
  • (c): Both (a) and (b)
  • (d): None of these
Answer: (c)– Both (a) and (b)
That’s all for the  Python programming Quiz – 8th Week Quiz Solution. if you have any questions, please comment down below, we will try to answer within the first 24 hours. I hope you liked this content. We will come to another week’s quiz. Thanks for reading.

Some More Answer

[1]
f = open(‘file.txt’)
print ( f.closed )
f.close()
print ( f.closed )
Answer:- False true
[2]
Which of the following function is used to read files in python:-
Read()
Readlines()
Readline()
All of the above


Answer:- All of the above
[3]
Which of the following is true :-
1. Read() returns a string and readlines() return line at a time
2. readlines()returns a list of lines and readline() returns one line at a time
3. Both a and b
4. None of the above
Answer:- Both a and b
[4]
Which of the following is true :-
1. file.closed() method is used to close a file.
2. file.close() method is used to check if a file is closed.
3. file.isClosed() is used to check if a file is closed or not.
4. None of the above


Answer:- file.closed() method is used to close a file.
[5]
Suppose a file named test.txt has content 1 2 3 4 5 6 7 in it.Now what will be the output of the following code :-
file = open(“test.txt”,’r’)
file.read(5)
Answer:-   1 2 3

Post a Comment

Previous Post Next Post