python - 将字符串更改为五个 python 的块
问题描述
如何更改字符串,以便每 5 个字符之间有一个空格?但是,我不希望在开头或结尾留出空间。
例如
"Yohomeyoverstack" will be "Yohom eyove rstac k"
"two" will be "two"
解决方案
使用slicing
前任:
s = "Yohomeyoverstack"
print( " ".join([s[i:i+5] for i in range(0, len(s), 5)]) )
输出:
Yohom eyove rstac k
推荐阅读
- javascript - 在关闭 Angular 材质对话框之前检查用户对 Reactive 表单的更改
- reactjs - npm 错误!在“...grity”附近解析时 JSON 输入意外结束:“sha512-kyAaTj”
- apache - 使用路径和查询字符串将包含目录路径和参数的 URL 重写为基于参数的 URL
- ios - 苹果商店连接链接
- c - 关于函数返回的 char 指针的最佳实践
- shiny - 无法使用 shinyapps.io 部署闪亮的应用程序
- microsoft-graph-api - 自己租户之外的用户无法在 Outlook 加载项中调用 getAccessTokenAsync(错误:13005 缺少此加载项的授权)
- javascript - 构建js文件vue cli项目
- java - Intellij 中缺少添加框架支持
- shell - 使用 sed 命令忽略完整文件路径