2017-02-22 71 views
1

我想在Python 3.4.3中转换对布尔值的评估。目前我的代码引发了一个IndexError异常。下面要说的一个切换到Python中的布尔表达式评估

lst = [1, 2, 3] 
if (len(lst)>3) & (lst[3]<2): 
    print('hello') 

给出了“IndexError:列表索引超出范围” 有没有什么办法让在Python 3.4.3这样的选择?

回答

0

不知道你为什么使用&(这是the bitwise and of x and y),而不是和?

应该是:

lst = [1, 2, 3] 
if (len(lst)>3) and (lst[3]<2): 
    print('hello')