ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print(oct(-8), hex(-255), bin(0), format(-5, 'b'))
- A. -0o10 -0xff 0b0 -101
- B. -0o10 -0xff 0b1 -101
- C. -8 -0xff 0b0 -101
- D. -0o10 -0xff 0 -101
Correct answer: A. -0o10 -0xff 0b0 -101
oct, hex and bin keep the minus sign for negative numbers and add their prefix after it. bin(0) is 0b0, and the b format gives -101 for -5.
More Python Programming questions
- What is printed? python n = 13 print(n ^ (n >> 1), [bin(i ^ (i >> 1)) for i in range(4)])
- What is printed? python print(~5 == -6, ~(-5) == 4, (-5) >> 1 == -2, -5 // 2 == -3)
- What is printed? python import unicodedata print(unicodedata.normalize('NFC', 'eu0301') == 'é', len(unicodedata.normalize('NFD', 'é'))…
- What is printed? python print('a1'.isalnum(), '١'.isalnum(), ' '.isspace(), ''.isspace(), 'u00a0'.isspace())
- What is printed? python def fermatinverse(a, p): return pow(a, p - 2, p) print(fermatinverse(3, 7) == pow(3, -1, 7), 3 fermatinverse(3, 7)…
- What is printed? python print(sorted(['beta', 'Alpha', 'alpha', 'Beta'], key=str.lower))