Detailed explanation of the usage of split in python:
split() function
Syntax: str.split(str="",num=string.count(str))[n]
Parameter description:
str: expressed as a separator, the default is a space, but Can not be empty(''). If there is no delimiter in the string, the entire string is treated as an element of the list
num: indicates the number of divisions. If the parameter num exists, it will only be divided into num 1 substrings, and each substring can be assigned to a new variable
[n]: means selecting the nth fragment
Note: When When using spaces as separators, empty items in the middle will be automatically ignored
1 2 3 4 5 6 |
|
The output results of the above examples are as follows:
1 2 |
|
Recommended tutorial: "Python Tutorial》
The above is the detailed content of Detailed explanation of the usage of split in python. For more information, please follow other related articles on the PHP Chinese website!