未分類

python3 で、指定した文字が最後に現れる場所を取得する

投稿日:

rfind を使うと、指定した文字が最後に現れる場所(インデックス)を取得することができる。

str1 = "12345abab"
result = str1.rfind("ab")
print(result)

結果

7

-未分類

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

tex で行に色をつける方法

xcolor パッケージを使っておく。rowcolor で指定する。 例 \usepackage[table]{xcolor} \begin{document} \begin{table} \begi …

no image

c++ で文字列が他の文字列を含むか判定する方法

文字列を含むかどうか判定するには、string の find を使う。見つからなかった場合は、std::string::npos を返す。 例 #include <iostream> #i …

no image

python3 で range からリストを生成する方法

list をrange を指定して初期化すれば良い。数を1つ飛ばしのリストも次のようにして作れる。 例 list1 = list(range(1,10,2)) print(list1) 結果 [1, …

no image

matplotlib で x軸・y軸ラベルをつける

plt.xlabel と plt.ylabel を使う。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, …

no image

tex で frac の意味

tex で frac コマンドは、分数(fraction)を表示するために使う。「バックスラッシュを付けた」 \frac であることに注意。 例 $\frac{2}{3}$ 結果