0
0

More than 3 years have passed since last update.

リストの中身を繋げて文字列にする方法

Last updated at Posted at 2020-01-24

リストの中身を繋げて文字列にする方法

案外文字列作るやり方がなかったので、初歩的ですが

l = ['a', 'b', 'c', 'd', 'e']

a = ' '.join(l)
print(a)

出力結果

'a b c d e'

結合する文字列は(str型)である必要があり。
要素が数値の場合は、例えばmap()関数などでstr型に変換する必要がある。

b = '_'.join(map(str, l))
print(b)

出力結果

'1_2_3_4_5'
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0