




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































if not a or b: print ("a") elif not a or not b and c: print ("b") elif not a or b or not b and a: print ("c") else: print ("d") (A) a (B) b (C) c (D) d Ans B Q8: What is the output of following code? class test: def init(self): print ("Hello World") def init(self): print ("Bye World") obj=test() (A) Hello World (B) Compilation Error (C) Bye World (D) Ambiguity Ans: C Q9: Which of the following is an invalid statement? (A) abc = 1,000, (B) a b c = 1000 2000 3000 (C) a,b,c = 1000, 2000, 3000 (D) a_b_c = 1,000, Ans: B Q10: Is it possible to use round function without any argument like round() (A) Yes (B) No Ans:: B Q11: What is an exception (A) Error (B) Compile time error (C) Run time error (D) None Ans: C Q12: Predict the output of following Python Programs. class Acc: def init(self, id): self.id = id id = 555 acc = Acc(111) print (acc.id) A) B) C)
Ans: A Q13:Predict the output of following Python Programs. counter = {} def addToCounter(country): if country in counter: counter[country] += 1 else: counter[country] = 1 addToCounter('China') addToCounter('Japan') addToCounter('china') print (len(counter)) A) B) C) D) Ans 3 Q 14: Predict the output of following Python Program count = 1 def doThis(): global count for i in (1, 2, 3): count += 1 doThis() print (count) A) B) C) D) ANS: A Q 15: dictionary = {1:'1', 2:'2', 3:'3'} del dictionary[1] dictionary[1] = '10' del dictionary[2] print (len(dictionary)) A) B) C) D) ANS: C Q 16:What is the output of the following piece of code? class A: def init(self):
main() a) 1 b) 0 c) 1 0 d) Error Ans: d Q21:Which of the following best describes polymorphism? a) Ability of a class to derive members of another class as a part of its own definition b) Means of bundling instance variables and methods in order to restrict access to certain class members c) Focuses on variables and passing of variables to functions d) having more than one form. Ans d Q22: What is the output of the following piece of code? class A: def init(self,x=3): self._x = x class B(A): def init(self): super().init(5) def display(self): print(self._x) def main(): obj = B() obj.display() main() a) 5 b) 3 c) Error, class member x has two values d) Error, protected class member can’t be accessed in a subclass Ans: a Q23: What is the output of the following piece of code? class A: def str(self): return '1' class B(A): def init(self): super().init() class C(B): def init(self): super().init() def main(): obj1 = B()
obj2 = A() obj3 = C() print(obj1, obj2,obj3) main() a) 1 1 1 b) 1 2 3 c) ‘1’ ‘1’ ‘1’ d) An exception is thrown Ans:a Q 24:A class in which one or more methods are only implemented to raise an exception is called an abstract class. True or False? a) True b) False Ans: b Q25: Inheritance shows. a) IS A Relationship b) HAS A Relationship c) USES Relationship d)None of the above. Ans: a
f.writelines(txt, list) f.seek(0,0) line = f.readlines() print ("Read Line: %s" % (line)) f.close() A. ['This', 'is', '1st', 'line ]� B. [] C. Error D. None Answer: C
if re.findall("^(astro)", i): print (i) C. print (re.findall("^(astro)", list1)) D. Both A and B Answer: D
D. Error Answer: B