python - 方法 strip() 没有从我的字符串中删除字符
问题描述
>>> y = 'This is string, should be without commas, but is not working'
>>> y = x.strip(",")
>>> y
'This is string, should be without commas, but is not working'
我想从这个字符串中删除逗号,但如上所示,strip 方法不想工作。
解决方案
该strip()
函数仅删除前导字符和尾随字符。而且因为你给它一个逗号作为参数,它只会删除前导和尾随逗号。
要从字符串中删除所有逗号,您可以使用该replace()
函数。所以你的第二行将变成:
y = x.replace(",", "")
推荐阅读
- sql - 如何处理动态查询
- javascript - jQuery 检查以测试 iframe 的内容未触发
- javascript - 为什么它适用于 nodejs 或任何其他 javascript 编译器?
- r - 如何测试数据框中的任何值是否超过限制
- google-api - Google API 调用:“此 URL 不支持 HTTP 方法 PUT。” URL 可能有什么问题?
- java - 基于两件事的重复数据删除数组
- javascript - 创建上传文件到谷歌云存储
- list - 为什么我在球拍中的递归函数给我传入的每个参数一个 0
- python - 为什么这个 if 语句不在 for 循环内执行?
- bootstrap-table - AJAX 数据返回但引导表未填充