41. What will be the output of the following Python code?
lst = [1, 2, 3]
lst[3]
lst = [1, 2, 3]
lst[3]
42. What will be the output of the following Python code?
def a():
try:
f(x, 4)
finally:
print('after f')
print('after f?')
a()
def a():
try:
f(x, 4)
finally:
print('after f')
print('after f?')
a()
43. What will be the output of the following Python code?
x=10
y=8
assert x>y, 'X too small'
x=10
y=8
assert x>y, 'X too small'
44. What will be the output of the following Python code?
#generator
def f(x):
yield x+1
g=f(8)
print(next(g))
#generator
def f(x):
yield x+1
g=f(8)
print(next(g))
45. What will be the output of the following Python code if the input entered is 6?
valid = False
while not valid:
try:
n=int(input("Enter a number"))
while n%2==0:
print("Bye")
valid = True
except ValueError:
print("Invalid")
valid = False
while not valid:
try:
n=int(input("Enter a number"))
while n%2==0:
print("Bye")
valid = True
except ValueError:
print("Invalid")
46. What is the purpose of the sys.exc_info() function in Python?
47. What will be the output of the following Python code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)