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
相关推荐
许彰午19 小时前
24_Java NIO核心组件
java·python·nio
lie..20 小时前
基于大模型的智能客服系统部署与使用(二):接入前端可视化界面
人工智能·python
光影62720 小时前
Python接口自动化测试----Requests库基础入门
开发语言·python·测试工具·pycharm·自动化
程序媛_20 小时前
【Python】连接PostgreSQL获取手机验证码
开发语言·python·postgresql
Kobebryant-Manba20 小时前
学习参数管理
pytorch·python·深度学习
是有头发的程序猿20 小时前
竞品分析 + 用户洞察自动化|基于 item_review 评论接口 + 多 AI Agent 实现淘宝评论全量采集与智能分析(附python源码)
java·python·自动化
信看20 小时前
Jetson Orin Quectel QMI 拨号上网
开发语言·python
骑士雄师20 小时前
课程导航LangGraph核心概念
python
SilentSamsara20 小时前
DuckDB + Python:嵌入式 OLAP 数据库的轻量分析实战
开发语言·数据库·python·微服务
爱上纯净的蓝天20 小时前
30 分钟上手 AtomCode:用它写一个 Python 批量整理文件/改名/生成报告小工具(新手教程)
python·开源·自动化脚本·atomcode·ai 编码助手