|
发表于 2022-8-5 21:36:42
|
显示全部楼层
'a','b','c'.split()
('a', 'b', ['c'])
'a,b,c'.split()
['a,b,c']
'a b c'.split
<built-in method split of str object at 0x10e8ae5b0>
'a b c'.split()
['a', 'b', 'c']
'a,b,c'.split(',')
['a', 'b', 'c']
'a,b,c'.split(',',1)
['a', 'b,c']
'a,b,c'.rsplit(',',1)
['a,b', 'c']
'a\nb\nc\n'.split('\n')
['a', 'b', 'c', '']
'a\nb\nc\n.split('\n')
SyntaxError: unexpected character after line continuation character
'a\nb\nc.split('\n')
SyntaxError: unexpected character after line continuation character
'a\nb\nc'.split('\n')
['a', 'b', 'c']
'1\n2\n3'.split('\n')
['1', '2', '3']
'1\r2\r3'.split('\r')
['1', '2', '3']
'1\r2\r3'.splitlines()
['1', '2', '3']
'1\n2\n3'.splitlines()
['1', '2', '3']
'1\n2\n\r3'.splitlines()
['1', '2', '', '3']
'1\n2\r\n3'.splitlines()
['1', '2', '3']
'1\n2\r\n3\n'.splitlines()
['1', '2', '3']
'1\n2\r\n3\n'.splitlines(True)
['1\n', '2\r\n', '3\n']
'!'.join('ctx','ccc')
Traceback (most recent call last):
File "<pyshell#56>", line 1, in <module>
'!'.join('ctx','ccc')
TypeError: str.join() takes exactly one argument (2 given)
'!'.join(['ctx','ccc'])
'ctx!ccc' |
|