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.

リストのコピー

Posted at
i = [1, 2, 3, 4, 5]
j = i
j[0] = 100
print('j = ', j)
print('i = ', i)

x = [1, 2, 3, 4, 5]
y = x.copy() # y =x[:]と書いても同じ処理が行えるがわかりにくいので推奨しない 
y[0] = 100
print('y = ', y)
print('x = ', x)

出力
j = [100, 2, 3, 4, 5]
i = [100, 2, 3, 4, 5]
y = [100, 2, 3, 4, 5]
x = [1, 2, 3, 4, 5]

X = 20
Y = X
Y = 5
print(Y)
print(X)

X = [ 'a', 'b']
Y = X
Y[0] = 'p'
print(Y)
print(X)

5
20
['p', 'b']
['p', 'b']

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?