ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(2**3**2, (2**3)**2, -2**2, (-2)**2, 2**-1**2)
- A. 512 64 -4 4 1.0
- B. 512 64 -4 4 0.5
- C. 2048 64 -4 4 0.5
- D. 512 64 -4 4 0.25
Correct answer: B. 512 64 -4 4 0.5
** is right-associative, so 2**3**2 is 2**9 = 512. Unary minus binds looser than **, so -2**2 is -4, and 2**-1**2 is 2**(-1) = 0.5.
More Python Programming questions
- What is printed? python print(float(254) + 1 == 254, 254 + 1 == float(254), 1e16 + 2 == 1e16 + 1)
- What is printed? python print(int('١٢٣'), int('0' 2 + '5'), int('5' + '0' 2), int(' t7n'))
- What is printed? python print(bin(-8 & 0xFF), (-8) >> 1, (-8) // 2, (-9) // 2, -9 >> 1)
- What is printed? python print(x := 7, x 2, [y := 3, y + 1])
- What is printed? python print('%s|%r' % ("it's", "it's"))
- What is printed? python print(ord('a') - ord('A'), chr(ord('A') + 32), 'Z'.lower() < 'a', 'z' > 'Z')