0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Python】リスト結合_備忘録

Last updated at Posted at 2021-01-24

#【構文】joinメソッド

i.join(iterable)
i:区切り文字
iterable:連結対象のリスト

data = ['りんご','ゴリラ','ラッコ','コアラ']
print(''.join(data)) #結果:りんご⇒ ゴリラ⇒ ラッコ⇒ コアラ

data1 = [1,2,3,4]
print(''.join(data)) #結果:TypeError: sequence item 0: expected str instance, int found

数値型リストをそのまま連結することができないためstr型に変更する必要がある。
※リスト内包表記

data1 = [1,2,3,4]
print(''.join([str(i) for i in data1]))
0
0
3

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?