python实现去除空格及tab换行符的方法
作者:LexSaints 时间:2023-09-27 08:16:05
1、先放个大招:去除字符串中所有的空格和tab换行符
str=" a b c de
f "
print(str.replace(" ","").replace("\n",""))
===输出结果===
abcdef
2、strip()方法,去除字符串开头或者结尾的空格
str = " a b c "
str.strip()
'a b c'
3、lstrip()方法,去除字符串开头的空格
str = " a b c "
str.lstrip()
'a b c '
4、rstrip()方法,去除字符串结尾的空格
str = " a b c "
str.lstrip()
' a b c'
5、replace()方法,去除字符串全部的空格
str = " a b c "
str.lstrip()
'abc'
来源:https://juejin.cn/post/6996910035494240287#hid-p4SsEF
标签:python,去除空格,tab,换行符
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
php+mysql实现简单登录注册修改密码网页
2024-04-30 08:49:54
![](https://img.aspxhome.com/file/2023/7/132787_0s.jpg)
[欣赏] 情景互动广告
2008-08-06 12:59:00
![](https://img.aspxhome.com/file/UploadPic/20088/6/200886131045714s.jpg)
Python 实现局域网远程屏幕截图案例
2021-05-13 13:43:43
![](https://img.aspxhome.com/file/2023/8/66788_0s.jpg)
使用Pytorch来拟合函数方式
2021-06-22 18:10:45
终于搞懂了Python中super(XXXX, self).__init__()的作用了
2022-01-04 00:35:44
SQL server 2005中设置自动编号字段的方法
2024-01-12 13:55:47
![](https://img.aspxhome.com/file/2023/6/102066_0s.png)
python使用PIL和matplotlib获取图片像素点并合并解析
2021-09-07 15:41:45
![](https://img.aspxhome.com/file/2023/6/93606_0s.png)
Access2K中的查询分析器
2008-11-20 16:40:00
Python爬虫中urllib3与urllib的区别是什么
2023-04-04 05:48:12
![](https://img.aspxhome.com/file/2023/6/112556_0s.png)
JS+HTML实现的圆形可点击区域示例【3种方法】
2024-04-10 10:42:30
pytorch 实现模型不同层设置不同的学习率方式
2023-11-20 00:29:25
JavaScript监听和禁用浏览器回车事件实例
2023-10-12 01:58:16
Python实现softmax反向传播的示例代码
2021-02-24 10:54:02
![](https://img.aspxhome.com/file/2023/3/84903_0s.png)
VSCode 使用Settings Sync同步配置(最新版教程,非常简单)
2022-10-17 08:50:47
![](https://img.aspxhome.com/file/2023/9/132469_0s.png)
SQLSERVER数据备份文件的分割备份方法
2024-01-15 15:30:39
![](https://img.aspxhome.com/file/2023/0/122350_0s.jpg)
介绍Python的Django框架中的静态资源管理器django-pipeline
2023-11-12 00:10:35
YOLOv5车牌识别实战教程(三)模型训练与评估
2021-01-07 19:15:43
![](https://img.aspxhome.com/file/2023/3/106993_0s.png)
一文带你了解MySQL基于规则的优化
2024-01-16 19:47:47
![](https://img.aspxhome.com/file/2023/7/69837_0s.webp)
uniapp开发打包成H5部署到服务器的详细步骤
2024-04-10 16:20:19
![](https://img.aspxhome.com/file/2023/1/136701_0s.jpg)
Mysql如何对json数据进行查询及修改
2024-01-14 06:29:56
![](https://img.aspxhome.com/file/2023/5/93905_0s.png)