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
相关推荐
用户83562907805132 分钟前
用Python轻松管理Word页脚:批量处理与多节文档技巧
后端·python
进击的松鼠43 分钟前
LangChain 实战 | 快速搭建 Python 开发环境
python·langchain·llm
小北方城市网1 小时前
第1课:架构设计核心认知|从0建立架构思维(架构系列入门课)
大数据·网络·数据结构·python·架构·数据库架构
我的offer在哪里1 小时前
Hugging Face:让大模型触手可及的魔法工厂
人工智能·python·语言模型·开源·ai编程
汤姆yu1 小时前
基于python大数据的协同过滤音乐推荐系统
大数据·开发语言·python
爱学习的小道长1 小时前
Python Emoji库的使用教程
开发语言·python
Data_agent2 小时前
Cssbuy 模式淘宝 / 1688 代购系统南美市场搭建指南
大数据·python
xyt11722281772 小时前
宗地四至提取工具
python·arcgis
程序员三藏2 小时前
接口自动化测试之 pytest 接口关联框架封装
自动化测试·软件测试·python·测试工具·测试用例·pytest·接口测试
江湖yi山人2 小时前
生产环境的log,上传到开发者的本地服务器
javascript·python