请参阅下面的代码和输出。第三个打印语句没有OUTPUT。在print(long_word [3:7])等位置改变的打印语句给出了输出(elin)。Jupyter Notebook,Python3打印功能:无输出,无错误
# [ ] print the first 4 letters of long_word
# [ ] print the first 4 letters of long_word in reverse
# [ ] print the last 4 letters of long_word in reverse
# [ ] print the letters spanning indexes 3 to 6 of long_word in Reverse
long_word = "timeline"
print(long_word[:4])
print(long_word[3::-1])
print(long_word[3:7:-1])
print(long_word[-1:-5:-1])
输出
time
emit
enil
是怎么回事?这个问题的情况也在下面的链接中提出。目前尚未解决。
正确,所以它应该是print(long_word [6:2:-1])这是有效的。人们会预期在上述碰撞情况中出现错误,不是吗? – Pankaj113
我认为这不是一个错误,因为你可以使用'print(long_word [2:15])'或'print(long_word [3:1])'。这只是一个理性的范围。 – danche