Python 之 split()
split() 用来实现对字符串 string 进行切片的操作
在 builtings.py 中的描述如下
def split(self, *args, **kwargs): # real signature unknown
"""
Return a list of the words in the string, using sep as the delimiter string.
sep
The delimiter according which to split the string.
None (the default value) means split according to any whitespace,
and discard empty strings from the result.
maxsplit
Maximum number of splits to do.
-1 (the default value) means no limit.
"""
pass
1. 默认操作: 按照空格进行划分
- split(): 按空格对字符串进行切片
测试代码如下:
arr = "3, 5, 7, 9, 12, 15, 18, 32, 66, 78, 94, 103, 269"
print(f"arr = '{
arr}'")
arr_split1 = arr.split()
print(f"\narr.split() = {
arr_split1}")
输出结果如下:
arr = '3, 5, 7, 9, 12, 15, 18, 32, 66, 78, 94, 103, 269'
arr.split() = ['3,', '5,', '7,', '9,', '12,', '15,', '18,', '32,', '66,', '78,', '94,', '