Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我不知道';我不明白一些示例代码的括号内是什么_Python - Fatal编程技术网

Python 我不知道';我不明白一些示例代码的括号内是什么

Python 我不知道';我不明白一些示例代码的括号内是什么,python,Python,我有一个简单的两行代码,但无法理解实际发生了什么 s = 'We\'re' + 'Here' print(s[4::2]) 结果就是eee。我看不出[4::2]是如何使代码打印eee的。这类似于[start:end:step],片地址可以写为s[start:end:step],并且可以删除start、stop或end中的任何一个。因此,s[4::2]是从序列的第四个和每第二个元素开始的(这里您删除了结尾部分)。这就是它返回eee s = 'We\'re' + 'Here' pr

我有一个简单的两行代码,但无法理解实际发生了什么

    s = 'We\'re' + 'Here'
    print(s[4::2])

结果就是eee。我看不出[4::2]是如何使代码打印eee的。

这类似于
[start:end:step]
,片地址可以写为s[start:end:step],并且可以删除start、stop或end中的任何一个。因此,s[4::2]是从序列的第四个和每第二个元素开始的(这里您删除了结尾部分)。这就是它返回
eee

s = 'We\'re' + 'Here'
print(s[4::2])