Im trying to find what all the bool methods do, i can't tell the difference between .bit_length()
and .conjugate()
, both return an int
, 0 if boolean = False, 1 if True
Asked
Active
Viewed 338 times
1

martineau
- 119,623
- 25
- 170
- 301
-
related: https://stackoverflow.com/questions/8169001/why-is-bool-a-subclass-of-int – jferard Jun 13 '20 at 07:06
2 Answers
1
Is this information helpful?
>>> help(bool.conjugate)
Help on method_descriptor:
conjugate(...)
Returns self, the complex conjugate of any int.
>>> help(bool.bit_length)
Help on method_descriptor:
bit_length(self, /)
Number of bits necessary to represent self in binary.
>>> bin(37)
'0b100101'
>>> (37).bit_length()
6

Terry Spotts
- 3,527
- 1
- 8
- 21
0
These methods are inherited from numeric type and don't make much sense for booleans. Perhaps you know that bool can be represented by one bit, so bit length is trivial. But what is conjugate
?
Well, for complex numbers it is the same number, but with imaginary part negated. So, (9 + 4j).conjugate()
is 9-4j
, but for real numbers it is just the same because their imaginary part is 0.
UPD:: In the first paragraph I wrongly assumed .bit_length()
returns length of internal representation in bits. It is wrong - as jferard pointed out, it returns number of significant bits (i.e. bits until most significant non-zero bit). I also overlooked the example in Terry's answer showing exactly this.

Marat
- 15,215
- 2
- 39
- 48
-
"bit length is trivial": `(False).bit_length()` returns `0`, not `1`... because `bit_length` returns the "number of bits necessary to represent self [an int] in binary" (the method is inherited from `int`, as `conjugate` is), not the size of the internal representation. – jferard Jun 11 '20 at 20:15
-
@jferard not that I used this method a lot (or at all), but it turns out all this time I had a wrong idea about what this method does. I'll update the answer, thank you. – Marat Jun 12 '20 at 02:12