What 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)
it will print bcac
for f(1) there is no exception error so it goes to else and finally
for f(2) there is a division zero error so it goes to except then finally
What will be the output of the following code?
class A:
a = 1
print (hasattr(A, ‘a’))
True
the hasattr() func checks for a specific object in a class, hasattr(class, “object”)
What will be the result of executing the following code?
class I:
def __init__(self):
self.s = ‘abc’
self.i 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=’’)
it will print abc