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

Pythonで「多次元リストの作成と要素の取得」の動作を確認してみた

Posted at

概要

Pythonで「多次元リストの作成と要素の取得」の動作を確認してみました。以下のページを参考にしました。

実装

以下のファイルを作成しました。

sample.py
stafflist = [["Yamada", 25], ["Suzuki", 38], ["Tanaka", 28]]
print(stafflist[0])
print(stafflist[1])
print(stafflist[2])

stafflist = [["Yamada", 25], ["Suzuki", 38], ["Tanaka", 28]]
print(stafflist[0][0])
print(stafflist[0][1])
print(stafflist[1][0])
print(stafflist[1][1])
print(stafflist[2][0])
print(stafflist[2][1])

stafflist = [["Yamada", 25], ["Suzuki", 38], ["Tanaka", 28]]
for p in [0, 1, 2]:
    for m in [0, 1]:
        print("[" + str(p) + "][" + str(m) + "] = ", end='')
        print(stafflist[p][m])

以下のコマンドを作成しました。

$ python3 sample.py 
['Yamada', 25]
['Suzuki', 38]
['Tanaka', 28]
Yamada
25
Suzuki
38
Tanaka
28
[0][0] = Yamada
[0][1] = 25
[1][0] = Suzuki
[1][1] = 38
[2][0] = Tanaka
[2][1] = 28

まとめ

何かの役に立てばと。

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