Can someone explain this syntax to me? I've searched through docs/blogs but can't find any mention of using booleans as indices for array slicing. I found this syntax in this script convert_base.py
:
is_negative = num_as_string[0] == '-'
num_as_string[is_negative:]
My guess is that False is being cast to 0 and True is being cast to 1. Does anybody know for sure or can point me to any documentation?
>>> a = [1,2,3]
>>> a[True:]
[2,3]
>>> a[False:]
[1,2,3]
>>> a[:False]
[]
>>> a[:True]
[1]
>>> a[False:True]
[1]
>>> a[True:True]
[]
>>> a[False:False]
[]
>>> a[True:False]
[]
>>> a[False::True+1]
[1,3]