未分類

python3 で、ある文字列で始まるかどうか判定する方法

投稿日:

文章が、ある文字列で始まるかどうかを判定するには startswith を使う。

str = "こんにちは。"
print(str.startswith('こん'))
print(str.startswith('にち'))

結果

True
False

-未分類

執筆者:


comment

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

関連記事

no image

python3 で、文字列の最後が特定の文字で終わるか判定する方法

endswith を使う。 例 str1 = “こんにちは” result1 = str1.endswith(“は”) result2 = str1.endswith(“わ”) print(resul …

no image

tex でアンダーバーを入力する方法

\_ でアンダーバーを入力できる。アンダースコアとも言う。 例 underbar a\_b 結果

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 で大括弧を表示する

大括弧を表示するには、\left[ または \right] を使う。 例 $\left[ \left( \frac{x}{y} \right) \right]$ 結果 片方だけの大括弧 片方だけのカッ …

no image

matplotlib で x, y軸・タイトルのフォントサイズを調整する

ラベルの fontsize で指定する。 例 import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2, 100) …