python - 使用索引创建新字符串
问题描述
做一个 python 问题并尝试创建一个在索引 n 处省略单个字符的新字符串。这有效:
newstr = str[:n] + str[n+1:]
但想知道为什么这不起作用:
newstr = str[:n] + str[-1:-(n+1)]
提前谢谢^
解决方案
推荐阅读
- angular - Angular Universal Docker 构建的问题
- node.js - 如何从节点 js 获取 Knex 中的 RAISE INFO/NOTICE?
- python - 列表理解:为一个列表中的项目分配值(如果它们包含在另一个列表中)时出现语法错误
- .net - Docker 构建找不到 EntityFramework.props
- java - 我应该如何使用另一个类的适配器在片段类中显示 listView
- linux - 在 AWS Linux 机器上升级 MariaDB
- java - Spring boot + Thymeleaf - 具有回退到默认值的多个模板解析器
- javascript - 如何在 javascript 中创建深度嵌套的对象?
- php - 项目获批后,使用 Youtube API 上传的视频仍标记为私有
- spring - 从 SpringBoot 中的 API 获取特定的响应值