>>> parseprint("l[1:2, 3]")
Module(body=[
Expr(value=Subscript(value=Name(id='l', ctx=Load()), slice=ExtSlice(dims=[
Slice(lower=Num(n=1), upper=Num(n=2), step=None),
Index(value=Num(n=3)),
]), ctx=Load())),
])
然而,这种语法无法在交互式Python shell中使用:
>>> foo = range(10)
>>> foo[1:2,3]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: list indices must be integers, not tuple
有人知道如何使用这个功能吗?
相关讨论:
foo[1:2,3]
是什么? - zondo