社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

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

mbwins10 • 5 年前 • 1779 次点击  

如果 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
 
1779 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Alec Alameddine
Reply   •   1 楼
Alec Alameddine    5 年前

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

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

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