Usage [of] road Rollo's Python Python Split () function

Python Split () function

Python split () delimiter specified by the string sections, if the parameter value is specified num, num + 1 sub-string is separated

split () method syntax:

str.split(str="", num=string.count(str)).

parameter

  • str - separator, default for all null characters, including spaces, linefeed (\ n-), tab (\ t) and the like.
  • num - the number of divisions. Defaults to -1, i.e., all separated.

 

return value

Returns a list of strings after division.

= STR " the this String Example .... IS WOW !!! " 
print (str.split ())        # a space as delimiter 
print (str.split ( ' i ' ,. 1))    # to a delimiter i 
print (str.split ( ' w ' ))      # to a delimiter w

 

Experience: str.split () values ​​can be used to segment, JSON format; also some of the data can be used to format

such as:

{
        xxxx:color
        xxxx:size  

}

# If you want to separate the two loop out color size property must be split this json, then come back loop

 

Guess you like

Origin www.cnblogs.com/rollost/p/11370439.html