3
4

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でリストを初期化する際の注意点

Posted at

list1 = list2 = []
のように初期化してしまうと、参照をコピーしてしまう。
慌てず焦らず
list1 = []
list2 = []
のようにする必要がある

test.py
>>> list1 = list2 = []
>>> list1.append(1)
>>> list2.append(2)
>>> print list1
[1, 2]
3
4
1

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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?