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?

More than 1 year has passed since last update.

PythonAdvent Calendar 2023

Day 6

Pythonで「for文を使った繰り返し」の動作を確認してみた

Posted at

概要

Pythonで「for文を使った繰り返し」の動作を確認してみました。以下のページを参考にしました。

実装

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

sample.py
mylist = ["Orange", "Peach", "Lemon"]
for val in mylist:
    print(val)

print("End")

mylist = ["Orange", "Peach", "Lemon", "Apple"]
for val in mylist:
    print("value:" + val)

mydict = {"L":"Lemon", "O":"Orage", "G":"Grapes"}
for mykey, myvalue in mydict.items():
    print("key:" + mykey + ", value:" + myvalue)

count = 0
mylist = ["Orange", "Peach", "Lemon", "Apple"]
for val in mylist:
    print("value:" + val)
    count += 1
else:
    print("要素の数 = " + str(count))

以下のコマンドを実行しました。

$ python3 sample.py 
Orange
Peach
Lemon
End
value:Orange
value:Peach
value:Lemon
value:Apple
key:L, value:Lemon
key:O, value:Orage
key:G, value:Grapes
value:Orange
value:Peach
value:Lemon
value:Apple
要素の数 = 4

まとめ

何かの役に立てばと。

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?