Python删除字符串中空格方法

一,方法一

repalce方法

python 复制代码
space_str = 'a b c'
cur_str = space_str.replace(' ', '')
print(cur_str)
# cur_str: abc

二,方法二

split和join方法

python 复制代码
space_str = 'a b c'
cur_str = "".join(space_str.split())
print(cur_str)
# cur_str: abc
相关推荐
半壶清水2 分钟前
【开源免费】使用 Python + Whisper + PyDub 自动切割长音频文件
开发语言·python·语言模型·开源·whisper
BoBoZz195 分钟前
BillboardTextActor3D 3D字体随镜头旋转
python·vtk·图形渲染·图形处理
天才测试猿10 分钟前
软件测试之bug分析定位技巧
软件测试·python·selenium·测试工具·职场和发展·测试用例·bug
課代表13 分钟前
Python 数据可视化:从单变量到多变量
开发语言·python·信息可视化·数据分析·变量·时间序列·文本分析
love_summer17 分钟前
深入理解Python流程控制:从算法设计到顺序执行机制(附代码)
python
山沐与山19 分钟前
【Python】深入理解Python Web框架:从Flask到FastAPI的并发之路
python·flask·fastapi
嫂子的姐夫20 分钟前
011-AES:深证信
爬虫·python·逆向
love530love23 分钟前
Flash Attention 2.8.3 在 Windows + RTX 3090 上成功编译与运行复盘笔记(2026年1月版)
人工智能·windows·笔记·python·flash_attn·flash attention·z-image
@zulnger29 分钟前
python 学习笔记(异常对象)
笔记·python·学习