未分類

python3 で、文字列を一文字ずつのリストに変換する方法

投稿日:

string を list() で変換すれば良い。

str1 = 'Good morning.'
list1 = list(str1)
print(list1)

結果

['G', 'o', 'o', 'd', ' ', 'm', 'o', 'r', 'n', 'i', 'n', 'g', '.']

-未分類

執筆者:


comment

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

関連記事

no image

python3 で文字列の最後の文字を削除する方法

文字列の最後に [:-1] を付けると、最後の文字を削除することができる。 例 res = ‘あいうえお'[:-1] print(res) 結果 あいうえ

no image

tex でファイ(φ、Φ)を入力する方法

小文字のファイ:φ、大文字のファイ:Φ串刺しでないファイ($\varphi$)も使われることがある。 例 $\phi, \varphi, \Phi$ 結果

no image

tex で かけ算の中点を入力する方法

かけ算に使うような中点を入力するには、 $cdot$ を使う。 例 $a = b \cdot c$ 結果

no image

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

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

no image

tex で脚注を表示する方法

\footnote を使う。 例 \footnote{this is a footnote.} 結果