ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print(True + True * 3, type(True + 1).__name__)
- A. 4 bool
- B. 6 int
- C. 4 int
- D. TrueTrueTrueTrue bool
Correct answer: C. 4 int
bool is a subclass of int, with True = 1. * binds tighter than +, so True + True * 3 = 1 + 3 = 4. Arithmetic on bools returns an int.
More Python Programming questions
- What is printed? python a = [1, 2, 3, 4, 5] a[1:3] = [9] a[::2] = [0, 0] print(a)
- What is printed? python d = {} d[1] = 'a' d[1.0] = 'b' d[True] = 'c' print(d)
- What is printed? python x = [1, 2, 3] for i in x: x.remove(i) print(x)
- What is printed? python fs = [lambda: i for i in range(3)] print([f() for f in fs])
- What is printed? python def f(x, lst=[]): lst.append(x) return lst a = f(1) b = f(2, []) c = f(3) print(a, b, c)
- What is printed? python def f(): try: return 1 finally: return 2 print(f())