0
0

More than 3 years have passed since last update.

ProgateでPython(辞書、while文、break、continue)

Posted at

python progate 学習コースⅡ

辞書

辞書のリストの要素取り出し方
for文を用いてリストを取り出し処理を行う
for 変数名 in 辞書:
ここで変数に要素のキーが一つずつ代入され、要素の値はキーが代入された変数を用いて取り出せる。

while文

while文の書き方
ある条件に当てはまる間繰り返し処理
while 条件式:
変数の値を更新し処理の前にチェック
Falseであれば処理終了
無限ループにならないように注意、特にインデントに気をつける

break

繰り返し処理を強制終了させる、if文などの条件分岐、while文などに用いる

numbers = [1,3,5,7,9]
for number in numbers:
print(number)
if number == 5:
break

console
1
3
5

continue

breakとは違いその週の処理だけをスキップする

numbers = [1,2,3,4]
for number in numbers:
if number % 2 == 0:
continue
print(number)

console
1
3

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