在 Python 中,strip 的用法有以下几种:
示例:s = " hello world ",s.strip() 结果为 "hello world"
示例:s = ">>>hello world<<<",s.strip("<>") 结果为 "hello world"
示例:s = " hello world",s.lstrip() 结果为 "hello world"
示例:s = ">>>hello world<<<",s.lstrip("<>") 结果为 "hello world<<<"
示例:s = "hello world ",s.rstrip() 结果为 "hello world"
示例:s = ">>>hello world<<<",s.rstrip("<>") 结果为 ">>>hello world"
需要注意的是,strip 只能去除字符串两端的字符,不会改变字符串内部的字符。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python怎么修改文件权限