ProgrammingHardAccenture pattern
What is printed?
What is printed?
def k():
try:
return "try"
except Exception:
return "except"
else:
return "else"
print(k())- A. try
- B. else
- C. except
- D. SyntaxError
Correct answer: A. try
Because the try block returns immediately with no exception raised, control never reaches the else clause (else only runs when the try block finishes WITHOUT hitting a return/exception on its last executed statement being a return exits straight away); the function returns 'try'.
More Python Programming questions
- What is printed? python s = "placement" print(s[-100:5])
- What is printed? python s = "abcdef" print(s[10:20])
- What is printed? python s = "abcdef" s2 = list(s) s2[1:3] = ["X", "Y", "Z"] print("".join(s2))
- What is printed? python s = "abc" print(s 0, type(s 0))
- What is printed? python s = "Mississippi" print(s.count("ss"), s.count("i"))
- What is printed? python l = [1, 2, 3, 4, 5] l[1:4] = [] print(l)