有人能解释一下这个语法吗?我已经查阅了文档/博客,但没有找到使用布尔值作为数组切片索引的任何提及。我在这个脚本
convert_base.py
中发现了这个语法:is_negative = num_as_string[0] == '-'
num_as_string[is_negative:]
我的猜测是False被转换为0,True被转换为1。有没有人确定这一点或者能够指引我查阅相关文档?
>>> 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]