# Python CodeRecipe|rsplit()の使い方

Home String Methods

# rsplit()の例1

Split a string into a list, using comma, followed by a space (, ) as the 
  separator:

    txt = "apple, banana, cherry"x = txt.rsplit(", ")
    print(x)

# rsplit()の定義及び使い方

The rsplit() method splits a string into a list, starting from the right. If no "max" is specified, this method will return the same as the split() method.

Note: When max is specified, the list will contain the specified number of elements plus one.

# rsplit()の構文

string.rsplit(separator, max)

# rsplit()の引数

パラメータ 説明

separator オプション. Specifies the separator to use when splitting the string. Default value is a whitespace

max オプション. Specifies how many splits to do. Default value is -1, which is "all occurrences"

# rsplit()の例2

Split the string into a list with maximum 2 items:

    txt = "apple, banana, cherry"# setting the max parameter 
    to 1, will return a list with 2 elements!x = txt.rsplit(", ", 1)
    print(x)

Home String Methods