Multiplying boolean with float?
In arithmetic, booleans are treated as integers. True
is treated as 1
and False
is treated as 0
.
>>> True + 1
2
>>> False * 20
0
>>> True * 20
20
In python, booleans are a subclass of int:
>>> isinstance(True, int)
True
They are basically 1 and 0:
>>> True * 1
1
>>> False * 1
0
See Why is bool a subclass of int?
True is 1
and False is 0
, as others have answered. So basically, what it does (and what should've been written) is:
p[i] * (pHit if hit else pMiss)