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.

【初心者向け】Pythonタプルとは。括弧で宣言された何か。

Last updated at Posted at 2022-05-30

文系やPython初心者向けの記事。
何かコードを渡されて解読しようにも、全く知識が無くて何で検索すれば良いのか分からない人向け。

・タプル
オブジェクトの宣言の仕方の1つらしい。
何かイコールの後に、括弧で囲まれたこんな感じのもの。
イミュータブル(とかいう変更ができないという意味)で、変更ができないらしい。

python_tuple = ('TEST0','TEST1','TEST2')

試してみる

・ソースコード

#!/usr/bin/python3

python_tuple = ('TEST0','TEST1','TEST2')
print("python_tuple[0]:" + python_tuple[0])
print("python_tuple[1]:" + python_tuple[1])
print("python_tuple[2]:" + python_tuple[2])
print("python_tuple[-1]:" + python_tuple[-1])
print("len(python_tuple): %d" % len(python_tuple))

・実行結果

./python_test.py
python_tuple[0]:TEST0
python_tuple[1]:TEST1
python_tuple[2]:TEST2
python_tuple[-1]:TEST2
len(python_tuple): 3

本ページ検索用の言葉
 イコールの後に括弧
 括弧の中にカンマ区切り

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