python字符串操作
来源:互联网 发布:mac系统u盘制作 编辑:程序博客网 时间:2024/06/06 19:06
phone = "2004-959-559\n 这是一个电话号码" print(phone) phone = phone.replace("\n", "") phone = re.sub(r'\n',"", phone) print( phone)
两个方法
但是注意 python 一般是返回型函数,不是在值上改
如果只是:
phone.replace("\n", "")phone还是更改之前的样子
" xyz ".strip() # returns "xyz" " xyz ".lstrip() # returns "xyz " " xyz ".rstrip() # returns " xyz" " x y z ".replace(' ', '') # returns "xyz"
list与str相互转换
import stringstr = 'abcde' list = list(str)list['a', 'b', 'c', 'd', 'e']str'abcde'str_convert = ''.join(list)str_convert'abcde'
str.split()
split翻译为分裂。 split()就是将一个字符串分裂成多个字符串组成的列表。split()当不带参数时以空格进行分割,当代参数时,以该参数进行分割。//---当不带参数时example:st0= ' song huan gong 'print(st0.split())结果为:['song', 'huan', 'gong']
阅读全文
0 0
- Python字符串操作
- Python字符串操作
- Python字符串操作
- python 字符串操作
- python字符串操作
- Python字符串操作
- Python字符串操作[转]
- Python字符串操作
- Python字符串操作
- Python学习---字符串操作
- python 中的字符串操作
- python------字符串连接操作
- python字符串操作
- python 字符串操作
- Python字符串操作
- python字符串操作
- Python字符串操作
- python 中的字符串操作
- spring security 自定义退出策略
- 大道至简,职场上做人做事做管理
- Linux服务器公钥私钥登录
- 面试题问题 小结01
- java线程安全之并发Queue(十三)
- python字符串操作
- 一道阿里笔试题解析--程序调优
- linux 如何知道用户是否是管理员
- 算法-循环链表[约瑟夫问题之进阶]
- JAVA改变图片大小,将图片改为Jpg格式
- Python(12)萌新也能看懂之——文件读写
- java.sql.SQLRecoverableException: IO 错误: Undefined Error
- jQuery基础
- Spring mvc的注解是如何工作的