ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(0x10 + 0o10 + 0b10, 1_0 + 0x_1, 1e1 + 1, 1j * 1j)
- A. 26 11 11.0 (-1+0j)
- B. 24 11 11.0 (-1+0j)
- C. 26 12 11.0 (-1+0j)
- D. 26 11 11 (-1+0j)
Correct answer: A. 26 11 11.0 (-1+0j)
Literals in hex, octal and binary give 16 + 8 + 2 = 26. Underscores are allowed in numeric literals, and 1e1 is a float, so the sum is 11.0. j * j is -1 as a complex number.
More Python Programming questions
- What is printed? python print(max(-0.0, 0), min(0, -0.0), -0.0 + 0, 0 - 0.0)
- What is printed? python a = 10 b = 3 print(a / b b == a, a // b b + a % b == a, a % b / b == (a / b) % 1)
- What is printed? python print(7 % 3 2, (7 % 3) 2, -7 % 3 2, 2 3 2 % 4)
- What is printed? python print(len(' a b '.split()), len(' a b '.split(' ')), len('anbn'.splitlines()), len('anbn'.split('n')))
- What is printed? python print(list('abc'.encode()), 'abc'.encode()[0] + 1, bytes('hi', 'ascii') == b'hi')
- What is printed? python x = 17 print(x.bitlength(), (x & -x).bitlength(), x.bitcount(), bin(x)[2:].zfill(8))