Latest web development tutorials

python3 RINDEX()メソッド

python3文字列 python3文字列


説明

発見間隔で:[エンド請う] RINDEX()は、一致する文字列が異常報告されていない場合は、オプションのパラメータを指定することができ、最後に出現する文字列str内のサブストリングの位置を返します。

文法

RINDEX()メソッドの構文:

str.rindex(str, beg=0 end=len(string))

パラメータ

  • STR - 検索文字列
  • 請う - 場所を探し、デフォルト値は0です
  • エンド - エンドの場所を見つけ、デフォルトでは文字列の長さです。

戻り値

一致する文字列が異常報告されていない場合は、最後に出現する文字列str内のサブストリングの位置を返します。

次の例では、使用するRINDEX()関数を示しています。

#!/usr/bin/python3
str1 = "this is really a string example....wow!!!"
str2 = "is"

print (str1.rindex(str2))
print (str1.rindex(str2,10))

次のように上記の出力結果の例は次のとおりです。

5
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    print (str1.rindex(str2,10))
ValueError: substring not found

python3文字列 python3文字列