赞
踩
split()分割的时候会把多个空格当做一个空格,split(’ ')分割的时候,多个空格会分割成多个空格。
split():
s1 = "we are family"#中间一个空格
s2 = "we are family"#中间两个空格
s3 = "we are family"#中间三个空格
s4 = "we are family"#中间四个空格
s1 = s1.split(" ")
s2 = s2.split(" ")
s3 = s3.split(" ")
s4 = s4.split(" ")
print(s1)#['we', 'are', 'family']
print(s2)#['we', '', 'are', '', 'family']
print(s3)#['we', '', '', 'are', '', '', 'family']
print(s4)#['we', '', '', '', 'are', '', '', '', 'family']
split(’ '):
s1 = "we are family"#中间一个空格
s2 = "we are family"#中间两个空格
s3 = "we are family"#中间三个空格
s4 = "we are family"#中间四个空格
s1 = s1.split()
s2 = s2.split()
s3 = s3.split()
s4 = s4.split()
print(s1)#['we', 'are', 'family']
print(s2)#['we', 'are', 'family']
print(s3)#['we', 'are', 'family']
print(s4)#['we', 'are', 'family']
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。