小编Cha*_*len的帖子

input().strip().split() 和 input().split() 有什么区别?

Split() function uses whitespace string as separator and removes the empty strings, so I think there is no use using strip() or rstrip() function to remove extra whitespace in head or tail. And here is my example:

a = ' \n   1 2 3 4     \n\n 5 \n\n \t'
b = a.rstrip().split()
c = a.split()
print('b =',b)
print('c =',c)
Run Code Online (Sandbox Code Playgroud)

The result turns out to be:

b = ['1', '2', '3', '4', '5']
c = ['1', '2', '3', '4', '5']
Run Code Online (Sandbox Code Playgroud)

It …

python split strip python-3.x

-1
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

python-3.x ×1

split ×1

strip ×1