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
相关推荐
_codemonster8 分钟前
python易混淆知识点(十六)lambda表达式
开发语言·python
superman超哥44 分钟前
仓颉Option类型的空安全处理深度解析
c语言·开发语言·c++·python·仓颉
2401_841495641 小时前
【LeetCode刷题】跳跃游戏Ⅱ
数据结构·python·算法·leetcode·数组·贪心策略·跳跃游戏
Data_agent1 小时前
OOPBUY模式淘宝1688代购系统搭建指南
开发语言·爬虫·python
张哈大1 小时前
AI Ping 上新限免:GLM-4.7 与 MiniMax-M2.1 实测对比
人工智能·python
乘凉~1 小时前
【Linux作业】Limux下的python多线程爬虫程序设计
linux·爬虫·python
xwill*1 小时前
pytorch中项目配置文件的管理与导入方式
人工智能·python
BBB努力学习程序设计2 小时前
Python模块与包:构建可维护的代码结构
python
BBB努力学习程序设计2 小时前
Python函数深度解析:从基础到高级装饰器
python·pycharm
抹除不掉的轻狂丶2 小时前
Java 日志框架完整指南:发展历史、核心组成与最佳实践
java·开发语言·python