python 中split 和 strip的实例详解

yipeiwu_com7年前Python基础

 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只能从两段开始删除,无法从中间删除。

同时不改变原字符串。这个方法,在实际使用的过程中并不多见。

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关文章

Django项目之Elasticsearch搜索引擎的实例

1.使用Docker安装Elasticsearch及其扩展 获取镜像,可以通过网络pull sudo docker image pull delron/elasticsearch-i...

python下setuptools的安装详解及No module named setuptools的解决方法

前言 python下的setuptools带有一个easy_install的工具,在安装python的每三方模块、工具时很有用,也很方便。 安装setuptools前先安装pip,请参...

Python BeautifulSoup [解决方法] TypeError: list indices must be integers or slices, not str

在python的Beautiful Soup 4 扩展库的使用过程中出现了 TypeError: list indices must be integers or slices, no...

Python模块的加载讲解

Python模块的加载讲解

不管是用import还是用from mmmm import *的方式导入模块,当程序运行之后,回头在看那个存储着mmmm.py文件的目录中,多了一个文件: $ ls mmm* mmm...

python之Character string(实例讲解)

1、python字符串 字符串是 Python 中最常用的数据类型。我们可以使用引号('或")来创建字符串,l Python不支持单字符类型,单字符也在Python也是作为一个字符串使用...