python - 如何从字符串中修剪空格(左右和空格之间)?
问题描述
我想删除句子中的任何额外空格我怎么能用python做到这一点?例如:
(" hello world") >>> ("hello world")
解决方案
str = " hello world "
str_clean = ' '.join(str.split())
print(str_clean)
hello world
编辑,我想我忽略了你的初始文本。
推荐阅读
- c# - 为什么我的控制器的数据在发布编辑后被重置
- ios - NavigationBar 中的 UISearchBar 颜色
- javascript - 如何在 JavaScript 工厂函数中使用原型?
- node.js - AWS 和 NodeJs 对外部 api 的 http 请求
- r - 被“没有适用于“filter_”的方法应用于类“字符”的对象的错误所困扰
- sql-server - 如何使用 GROUP BY 创建触发器
- c++ - 为 codechef 中的每个代码获取 SIGEMT 错误
- python - Pandas 查找值是否包含在键值对中的方法
- jquery - 如何使用 1 个“X”关闭按钮关闭 div 元素,在多个 div 上实现,每个按钮关闭 1 个 div?
- c++ - 将相位(角度)转换为复数值