ProgrammingHardProduct Company SDE · Python internals
What does the following Python 3 code print? try: def f(a, b): return a + b f(1) except TypeError: print("TypeError")
- A. None
- B. TypeError
- C. 1
- D. NameError
Correct answer: B. TypeError
f requires two positional arguments; calling it with only one raises TypeError for the missing argument.
More Python Programming questions
- What does the following Python 3 code print? try: x = [1, 2] + (3, 4) except TypeError: print("TypeError")
- What does the following Python 3 code print? class MyErr(Exception): pass try: raise MyErr("custom") except MyErr as e: print("caught", e)
- What does the following Python 3 code print? def f(): for i in range(3): if i == 1: continue print(i, end="") print() f()
- What does the following Python 3 code print? def f(): for i in range(5): if i == 3: break else: print("else-no-break") print(i) f()
- What does the following Python 3 code print? def f(): for i in range(3): pass else: print("else-ran") f()
- What does the following Python 3 code print? while False: print("never") else: print("while-else")