未分類

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

投稿日:

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

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

結果

7

-未分類

執筆者:


comment

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

関連記事

no image

tex で文字色を RGB で指定する

文字色を RGB で指定する。例では、\definecolor で、「samplecolor」という色を定義して使っている。 例 \usepackage{xcolor}\begin{document} …

no image

matplotlib で縦横の罫線を出力する

罫線を出力するには、pyplot.grid を使う。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 …

no image

tex で行に色をつける方法

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

no image

tex で数式モード内に普通の文字列を入力する方法

\textrm を使う。 例 $$y = f (x) \hspace{1cm} \textrm{This is a function.}$$ 結果

no image

tex で打ち消し線を入力する方法

次のように入力すればよい。打ち消し線は、英語で strikethrough と呼ぶ。 例 \usepackage[normalem]{ulem} \begin{document} Good \sout …