python 中split 和 strip的实例详解
2019/7/13 22:56:40
本文主要是介绍python 中split 和 strip的实例详解,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
python 中split 和 strip的实例详解
一直以来都分不清楚strip和split的功能,实际上strip是删除的意思;而split则是分割的意思。
python中strip() 函数和 split() 函数的理解,有需要的朋友可以参考下。
splite 和strip 都是Python 对字符串的处理。
splite 意为分割,划分。
a='123456' a.split('3')
输出为 [‘12', ‘456']
可以看到,使用何种字符切割,该字符也被略去。例如这里的字符“3”
strip 意为去除,删除。
a='123456' a.strip('1')
这里可以运行下,输出'23456'
值得注意的是,strip只能从两段开始删除,无法从中间删除。
同时不改变原字符串。这个方法,在实际使用的过程中并不多见。
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
这篇关于python 中split 和 strip的实例详解的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python