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 1 year has passed since last update.

タプル

Posted at

タプルとは、リスト同様に複数の要素を格納できる
タプルはリストと違って中身を更新することができない
要素の変更をしたくないときに有効である

py.qitta.py
#  タプルの学習
a = (1, 2, 3)
print(a, 'タプルの型は',type(a))

タプルの要素を取り出す方法

py.qiita.py
#  アンパックすると、要素の取り出しが可能
one, two = (1, 2)
print(one, two)

注意点

py.qiita.py
#  練習
t1 = (1, 2)
t2 = (3, 4)
print('t1のID: ', id(t1))
print('t2のID: ', id(t2))

t1 = t1 + t2
print(t1)
#  ここで、t1が更新できているのは、IDが違うから
#  元々あったt1が更新できたわけではなく、新しいタプルが作成されたということ
print('新しいt1のID', id(t1))

0
0
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
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?