ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(bin(5 & -5), (5).bit_count(), (-5).bit_count(), (-5).bit_length())
- A. 0b1 2 2 2
- B. 0b1 2 2 3
- C. 0b101 2 2 3
- D. 0b1 2 0 3
Correct answer: B. 0b1 2 2 3
5 & -5 isolates the lowest set bit of 5, which is 1. bit_count and bit_length use the magnitude of -5, which is 101 in binary, so 2 bits are set and 3 bits are needed.
More Python Programming questions
- What is printed? python print(0b1 << 100 > 299, (1 << 100).bitlength(), len(bin(1 << 100)) - 2)
- What is printed? python print(float(3) / 2 == 1.5, 3 // 2.0, 3 / 2.0 // 1)
- What is printed? python print(round(3.14159, 3), round(2.5e-7, 7), round(123.456, -1), round(-0.0001, 2))
- What is printed? python print('Hello World'.swapcase().title(), 'tEST'.capitalize(), 'x'.isalpha(), '1.5'.isdigit(), '١٢'.isdigit())
- What is printed? python print('ab' in 'cabd', '' in 'abc', 'abc'.index(''), len('abc'[3:]), len('abc'[4:]))
- What is printed? python print(sum(map(int, str(220))), len(str(350)), str(105)[::-1].count('0'))