Py学习  »  Python

为什么Python要返回这个?[副本]

mbwins10 • 5 年前 • 1947 次点击  

如果 my_string = "This is MY string!" ,为什么 print(my_string[0:7:5]) 返回“Ti”而不是 “T i”是因为“This”和“is”之间有一个空格?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52039
文章 [ 1 ]  |  最新文章 5 年前
Alec Alameddine
Reply   •   1 楼
Alec Alameddine    5 年前

你只需要 understand slice notation : string[start:stop:step]

从字符0开始(第一个字符)。这是一个 T . 在第7个字符(第八个字符)处停止。这是 i . 第五步。这意味着只显示这两个字符,而bc之间的距离从开始到结束都不小于25。

空间(字符4)没有包含的理由。