Format of:
1 str.split ([SEQ [, Maxsplit]]) We are most used to!
Name, age | Another user name, age
Name:haha,age:20|name:python,age:30|name:fef,age:55
Then we can cut the string object into a list by the split method of the string object.
A = ' name:haha,age:20|name:python,age:30|name:fef,age:55 '
Print A.split (' | ')
return Result:
[' name:haha,age:20 ', ' name:python,age:30 ', ' name:fef,age:55 ']
With the above introduction, I believe you have a better understanding of Python string split
Example
| The code is as follows |
Copy Code |
s= ' Server=mpilgrim;uid=sa;database=master;pwd=secret ' >>> s.split (";") [[' Server=mpilgrim ', ' uid=sa ', ' database=master ', ' Pwd=secret ']] |
If your separator is one or more spaces, then you do not have to give any parameters, that is, directly using Str.split () can
| code is as follows |
copy code |
| >> > fly= ' bigzhu, flyzhu ' >>> fly.split () [' Bigzhu, ', ' Flyzhu '] >>> fly= ' bigzhu, Flyzhu ' >>> fly_list=fly.split () >>> print fly_list [' Bigzhu, ', ' Flyzhu '] >>> fly= '. Join (fly_list) >>> print fly Bigzhu, flyzhu >>> fly.split (', ') [' Bigzhu ', ' Flyzhu '] |