10行に押し込みました。 ポイントは Time と from..import と for..else。 ライブラリ「time」から、「localtime」をインポートします。 ライブラリ「time」は次のように説明されています。 time --- 時刻データへのアクセスと変換 このモジュールでは、時刻に関する ...
for文の次は、Pythonのwhile文について説明します。 while文の基本的な構文 指定した条件が真(True)である間、繰り返し処理(ループ)を行う制御フロー文です。一般的には、以下のように利用します。 while condition: # code to be executed ここで、conditionはループが ...
次に、プログラムの流れを制御する制御文を説明しましょう。制御文は大別すると「分岐」と「ループ」に分かれます。 分岐は容易に理解できる機能で、基本は「if文」です。先ほどの「if i % 2 == 0」はif文の例だったのです。if文は次のように使います。
The else statement is one such statement that can be used in loops even without the if conditional statement. Else is only functional when the loop is terminated normally. If the loop is terminated ...