擅长:python、mysql、java
<p>Python语法定义了何时可以使用slice操作符:</p>
<pre><code>trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
subscriptlist: subscript (',' subscript)* [',']
subscript: test | [test] ':' [test] [sliceop]
sliceop: ':' [test]
</code></pre>
<p><code>test</code>几乎是任何表达式,但只有在<code>subscriptlist</code>中才能使用slice运算符。所以,是的,用于下标时的方括号是重要的,但是用于列表的方括号不会神奇地允许您编写切片,也不能将切片放入恰好位于下标中的任意表达式中。在</p>
<p>如果你在没有订阅的时候想要切片,你必须写<code>slice(a,b,c)</code>。在</p>