未分類

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

投稿日:

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

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

結果

True
False

-未分類

執筆者:


comment

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

関連記事

no image

tex で文字列を変数として設定する方法

\newcommand を使って指定する。入力の数は自由に指定できる。 例 \newcommand{\variable}[2]{Hello #1. Good #2.} \variable{Taro}{ …

no image

tex で差集合の記号を入力する方法

\setminus を使う。 例 $A \setminus B$ 結果

no image

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

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

no image

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

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

no image

tex で累乗根を入力する方法

$\sqrt[n]{2}$のようにする。 例 $\sqrt[n]{2}$ 結果