原博客地址:http://www.aobosir.com/blog/2016/12/01/python-string-split/
- 使用的电脑系统:Windows 10 64位
- 使用的开发集成环境:PyCharm 2016.1.4
- 使用的Python的版本:python2.7.10 或者 python 3.5.0
本博文对Python2和Python3都适用。
参考网站:Python split()方法
Python split()通过指定分隔符对字符串进行切片,返回一个列表。
语法:
zifuchuang.split(str, num)
- str 分隔符
- num 分割次数
实例:
str = r'D:\WorkSpace\test_ws\Git(GitHub)'
l = str.split('\\')
print(l)
print(str.split('\\', 1))
输出:
['D:', 'WorkSpace', 'test_ws', 'Git(GitHub)']
['D:', 'WorkSpace\\test_ws\\Git(GitHub)']

本文介绍了 Python 中 split() 方法的基本用法,包括如何通过指定分隔符来分割字符串,并返回相应的列表。文中提供了使用 PyCharm 在 Windows10 系统下 Python 2.7.10 和 Python 3.5.0 的示例代码。

1242

被折叠的 条评论
为什么被折叠?



