当前位置:网站首页>第二章 第四节:替换和切割
第二章 第四节:替换和切割
2022-07-20 20:49:00 【中亿丰数字科技有限公司】
Python基础入门(全套保姆级教程)
第二章
第四节:替换和切割
strip() 去掉字符串左右两端的空白符(空格, \t, \n)
s = " 你好, 我叫 周杰伦 "
s1 = s.strip()
print(s1)
strip()非常重要,下面是登陆账号时,左右空格去除的案例如下
username = input("请输入用户名:").strip()
password = input("请输入密码:").strip()
if username == "admin":
if password == "123456":
print("登录成功")
else:
print("登录失败!")
else:
print("登录失败!")
replace(old, new) 字符串替换,去掉所有空格
s = "你好啊, 我叫赛利亚"
s1 = s.replace("赛利亚", "周杰伦")
print(s1)
a = "hello i am a good man!"
a1 = a.replace(" ", "") # 去掉所有的空格
print(a1)
split(用什么切割) 字符串切割, 用什么切, 就会损失掉谁.
a = "python_java_c_c#_javascript"
lst = a.split("_") # 切割之后的结果会放在列表当中
print(lst)
lst = a.split("_java_")
print(lst)
总结:
strip() 可以去掉字符串左右两端的空白(空格, \t, \n)
replace() 字符串替换,它也可以去掉所有的空格
split() 对字符串进行切割,split(用什么切割) 字符串切割, 用什么切, 就会损失掉谁.
边栏推荐
- Web3 traffic aggregation platform starfish OS interprets the "p2e" ecosystem of real business
- It is said that only the great God knows the function of this capacitor
- Research Report - visible light communication and visible light positioning
- 国债逆回购安全吗 怎么卖出去
- leetcode:407. 接雨水 II
- Visual Studio 好用的插件分享
- 7.19模拟赛总结
- [kaggle] how to effectively avoid oom (out of memory) and long alchemy process
- Kingbasees database administrator's Guide -- 16 automatic maintenance tasks of management database
- leetcode:407. Connected to rainwater II
猜你喜欢
TDSQL PG版节省30%磁盘空间的同时如何保障数据安全?|DB·洞见
SQL: SELECT t.`app_ code`, SUM(t.`success_num`) AS success_ num, SUM(t.`
Rasterization comprehensive analysis
虚拟机内核参数永久生效配置
DAMA-第九章(文件与内容管理)
Expose the insider of Apache Doris data Lake analysis technology? Rare earth Developers Conference free registration!
Winform窗体使用Assembly实例化及传参
leetcode:42. Connect rainwater
The first blog experts to obtain entity certificates on the list
英文关键字文字拆分之语意匹配
随机推荐
Web3流量聚合平臺Starfish OS,詮釋真正商業的“P2E”生態
欧菲光:已布局运动相机、智能家居等光学镜头 / 影像模组,部分产品已实现量产
Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
Automatic invoice processing - get rid of the shackles of paper and data input, automate workflow and exception handling, and significantly shorten the audit preparation time
IDEA 2021 自动生成serialVersionUID
[kaggle] how to effectively avoid oom (out of memory) and long alchemy process
php 跨域解决方案
Web3 traffic aggregation platform starfish OS gives players a new paradigm experience of metauniverse
虚拟机双网卡配置
C#与SAP接口对接
魑魅魍魎
DAMA-第六章(数据存储与操作)
基于可见光通信的移动机器人室内定位及物联网应用
Kingbasees database administrator's Guide -- 15.1 Manage views
DAMA-第十二章(元数据管理)
leetcode:42. 接雨水
C语言详解系列——goto语句的讲解和循环语句的简单练习题
TCP sliding window explanation (very practical)
Yunna Xianning communication machine room dynamic loop monitoring system, telecom dynamic loop monitoring system
同一工作空间下引用不同包的头文件