1
2

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 5 years have passed since last update.

Pythonで配列(list)を結合

Last updated at Posted at 2018-08-30

#Pythonでlistを結合したい
以下のような二つの配列(list1,list2)がある

list1 = [1]
list2 = [2,3]

この時,結合するメソッドは二つありappendとextendだ

list1.append(list2)
print(list1) # [1,[2,3]]

list1.extend(list2)
print(list1) # [1,2,3]

この時注意することは初めにlist1やlist2のような配列を宣言しておく必要がある.

そのため初めが空の配列を想定するなら

list1 = []

といった配列を宣言すること

1
2
2

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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?