Home > other > STR. The split (sep) what circumstances will remove sep?
STR. The split (sep) what circumstances will remove sep?
Time:10-03
For example:
"An apple a day". The split (' a ')
To the result of the output: [', 'n', 'pple', 'd', 'y']
The
Def split (s) :
Return s.s plit (' a ')
S="an apple a day"
Print (s.s plit ())
The output result is: [' an ', 'apple', 'a', 'day']
And return the s.s plit (' a ') of the separator to other characters, such as' c ', the output is still [' an ', 'apple', 'a', 'day']
But "an apple a day". The split (' c ') output for [' an apple a day]
CodePudding user response:
Look not to understand, s.s plit () is equal to the s.s plit (None) > S.s plit (None) [' an ', 'apple', 'a', 'day'] > S.s plit () [' an ', 'apple', 'a', 'day'] > S.s plit (' a ') [' ', 'n', 'pple', 'd', 'y'] > S.s plit (' c ') [' an apple a day] Space is not normal?