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?

CodePudding user response:

reference 1/f, ice wind of reply:
don't 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?

Such output space is normal, I was called into question is the following function to output the results of the
S="an apple a day"
def split (s) :
Return s.s plit (' a ')

Print (s.s plit ())
Output [' an ', 'apple', 'a', 'day']
Just then at the next, the understanding, the red not cited in the parts of function, performed only
S="an apple a day"
Print (s.s plit ())
So is [' an ', 'apple', 'a', 'day']

CodePudding user response:

Resolved to see
def split (s) :

Return s.s plit (' a ')


S="an apple a day"

Print (s.s plit ())
The red part is the deceiver and reference function
  • Related