This article mainly introduces the use of Split () method in Python to split strings used to introduce, is the basic knowledge of Python, the need for friends can refer to the
The split () method returns a list of all the words in the string, using STR as the delimiter (if all spaces are not specified), optionally limiting the current division to number Num.
Grammar
The following is the syntax for the Split () method:
?
1 |
Str.split (str= "", Num=string.count (str)). |
Parameters
STR-This is any delimiter and is a space by default.
Num-This is the number of rows to split.
return value
This method returns the list of rows.
Example
The following example shows the use of the split () method.
?
1 2 3 4 5 |
#!/usr/bin/python str = "Line1-abcdef nline2-abc NLINE4-ABCD"; Print Str.split (); Print Str.split (', 1); |
When we run the above program, it produces the following results:
?
|
[' line1- ABCdef ', ' line2-abc ', ' LINE4-ABCD '] [' line1-abcdef ', ' nline2-abc nline4-abcd '] |