ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(10**18 + 1 == 1000000000000000001, 2**31 - 1 + 1, -(2**31), (2**31) * (2**31) == 2**62)
- A. True 2147483647 -2147483648 True
- B. True 2147483648 -2147483648 True
- C. True 2147483648 -2147483647 True
- D. False 2147483648 -2147483648 True
Correct answer: B. True 2147483648 -2147483648 True
Python integers never overflow, so 2**31 - 1 + 1 is exactly 2**31 and the product of two 2**31 values equals 2**62. Fixed-width C or Java ints would wrap here.
More Python Programming questions
- What is printed? python s = 'a' for i in range(3): s = s + s[::-1] + str(i) print(s, len(s))
- What is printed? python t = (1, 2, 3) t += (4,) u = t t = 2 print(t, u, t is u, len(t) len(u))
- What is printed? python lst = [1, 2, 3] lst2 = lst lst = 2 lst2 += [9] print(lst, lst2, lst is lst2)
- What is printed? python print(f'{0.1 + 0.2:.17g}', f'{1/7:.10f}', f'{100/3:.0f}', f'{2.345:.2f}')
- What is printed? python a = [3, 1, 2] b = sorted(a, key=lambda x: -x) a.sort(reverse=True) print(a == b, a, b)
- What is printed? python print(pow(7, 222, 10), pow(7, 222, 1000), 7222 % 1000, pow(-7, 3, -5))