# rindex()の使い方

Home String Methods

# rindex()の例1

Where in the text is the last occurrence of the string "casa"?:

    txt = "Mi 
    casa, su casa."x = txt.rindex("casa")print(x)

# rindex()の定義と使い方

rindex()関数は最後の 指定された値のオカレンス。 値が見つからない場合、rindex()関数では例外が発生します。 rindex()関数は、 rfind()で呼び出されます。次の例を参照してください。

# rindex()の構文

string.rindex(value, start, end)

# rindex()の引数

パラメータ 説明

value:必須. The value to search for

start オプション. Where to start the search. Default is 0

end オプション. Where to end the search. Default is to the end of the string

# rindex()の例2

Where in the text is the last occurrence of the letter "e"?:

    txt = "Hello, welcome to my world."x = txt.rindex("e")print(x)

# Example

Where in the text is the last occurrence of the letter "e" when 
  you only search between position 5 and 10?:

    txt = "Hello, welcome to my world."x = txt.rindex("e", 
    5, 10)print(x)

# Example

If the value is not found, the rfind() method returns -1, but the rindex() 
  method will raise an exception:

    txt = "Hello, welcome to my world."
    print(txt.rfind("q"))print(txt.rindex("q"))

Home String Methods