Latest web development tutorials

python3のRFIND()メソッド

python3文字列 python3文字列


説明

一致がない場合はPythonのRFIND()は、文字列の最後に出現する位置を返します-1が返されます。

文法

RFIND()メソッドの構文:

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

パラメータ

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

戻り値

これは、一致するものがない場合は-1が返され、文字列の最後に出現する位置を返します。

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

#!/usr/bin/python3

str1 = "this is really a string example....wow!!!"
str2 = "is"

print (str1.rfind(str2))

print (str1.rfind(str2, 0, 10))
print (str1.rfind(str2, 10, 0))

print (str1.find(str2))
print (str1.find(str2, 0, 10))
print (str1.find(str2, 10, 0))

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

5
5
-1
2
2
-1

python3文字列 python3文字列