Questions Bank November 5, 2022 Comments Off on Questions Bank What is the expected result of executing the following code? def I(): s = ‘abcdef’ for c in s[::2]: yield c for x in I(): print(x, end=”)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2Look at the code below: my_tuple = (0, 1, 2, 3, 4, 5, 6) # Insert line of code here. print(foo) Which snippet would you insert in order for the program to output the following result (list): [2, 3, 4, 5, 6]OpenProgrammingAnswers asked 2 years ago • Python Essentials 2Look at the code below: my_list = [1, 2, 3] # Insert line of code here. print(foo) Which snippet would you insert in order for the program to output the following result (tuple): (1, 4, 27)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2Select the true statements. (Select two answers)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What keyword would you use to define an anonymous function?OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class I: def __init__(self): self.s = ‘abc’ self.i = 0 def __iter__(self): return self def __next__(self): if self.i == len(self.s): raise StopIteration v = self.s[self.i] self.i += 1 return v for x in I(): print(x,end=”)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class Ex(Exception) def __init__(self, msg): Exception.__init__(self, msg + msg) self.args = (msg,) try: raise Ex(‘ex’) except Ex as e: print(e) except Exception as e: print(e)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? try: raise Exception(1,2,3) except Exception as e: print(len(e.args))OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? def f(x): try: x = x / x except: print(“a”,end=”) else: print(“b”,end=”) finally: print(“c”,end=”) f(1) f(0)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class A: v = 2 class B(A): v = 1 class C(B): pass o = C() print(o.v)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class A: def __str__(self): return ‘a’ class B: def __str__(self): return ‘b’ class C(A, B): pass o = C() print(o)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class A: def a(self): print(‘a’) class B: def a(self): print(‘b’) class C(B,A): def c(self): self.a() o = C() o.c()OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class A: pass class B(A): pass class C(B): pass print(issubclass(C,A))OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class A: def __str__(self): return ‘a’ class B(A): def __str__(self): return ‘b’ class C(B): pass o = C() print(o)OpenProgrammingAnswers asked 2 years ago • Python Essentials 2What will be the result of executing the following code? class A: def __init__(self): pass a = A(1) print(hasattr(a,’A’))OpenProgrammingAnswers asked 2 years ago • Python Essentials 2 Share Facebook Twitter Stumbleupon LinkedIn Pinterest