未分類

python3 で文字列のリストを結合して1つの文字列にする方法

投稿日:

リストに対して、join メソッドを実行する。

list1 = ['hello, ','good ', 'morning']
str1 = ''.join(list1)
print(str1)

結果

hello, good morning

-未分類

執筆者:


comment

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

関連記事

no image

tex で同値記号(⇔)を入力する方法

同値記号を入力するには、\Leftrightarrow を使う。 例 $b \leftrightarrow c$, $b \Leftrightarrow c$

no image

python で文字列の長さを表示する方法

len を使う。 例 length = len(‘文字列あいうえお’) print(str(length)) 結果 8

no image

tex でインテグラルが小さくなる→大きくする方法

文章中でインテグラル(積分記号)を大きくするには、\displaystyle と書けばよい。 例 usual $\int \frac{ax+b}{cx+d} dx$display style $\di …

no image

c++ で文字列を「区切り文字」を使って分ける方法

string の find を使って、区切り文字の場所を取得し、その位置で区切る。 例 #include <iostream> #include <string> using namesp …

no image

python3 でカンマの入った数値の文字列を数値に変換する方法

replace と int 変換を組み合わせる。 例 str1 = ‘1,234,567’ int1 = int(str1.replace(‘,’,”)) print(int1) 結果 123456 …