首页 > 解决方案 > 使用索引创建新字符串

问题描述

做一个 python 问题并尝试创建一个在索引 n 处省略单个字符的新字符串。这有效:

newstr = str[:n] + str[n+1:]

但想知道为什么这不起作用:

newstr = str[:n] + str[-1:-(n+1)]

提前谢谢^

标签: pythonstringindexing

解决方案


推荐阅读