【6-1】
▲if節だけの場合
-------------------
>>> a = 5
>>> if a == 5:
...     print("True")
...
True
-------------------


▲else節を使う場合
-------------------
>>> a = 5
>>> if a == 1:
...     print("True")
... else:
...     print("False")
...
False
-------------------


▲複数の分岐を持つ条件分岐
-------------------
>>> a = 5
>>> if a == 2:
...     print("a is 2.")
... elif a == 5:
...     print("a is 5.")
... else:
...     print("etc.")
...
a is 5.
-------------------


▲文字列の評価
-------------------
>>> a = "apple"
>>> if a == "apple" and True:
...     print("True")
...
True
-------------------


▲文字列とブール値の組み合わせ
-------------------
>>> a = "apple"
>>> if a == "peach" or True:
...     print("True")
... else:
...     print("False")
...
True
-------------------


【6-2】
▲for文での使い方
-------------------
>>> for i in range(10):
...     if i == 3:
...         break
...     print(i)
...
0
1
2
-------------------


▲while文での使い方
-------------------
>>> num = 0
>>> while True:
...     if num > 5:
...         print(num)
...         break
...     num = num + 1
...
6
-------------------


▲if文での使い方
-------------------
>>> num = 1
>>> while num <= 5:
...     print(num)
...     if (num % 2) == 0:
...         break
...     num = num + 1
... else:
...     print('stop')
... 
1
2
-------------------


▲try文での使い方
-------------------
>>> try:
...      for i in range(10):
...          if i > 4:
...              break
...          print(i)
... except:
...      print("error")
... else:
...      print("success")
... finally:
...      print("end")
... 
0
1
2
3
4
success
end
-------------------


【6-3】
▲単純なforループ
-------------------
>>> list_num = [1, 2, 3, 4]
>>> for i in list_num:
...     print(i)
...
1
2
3
4
-------------------


▲range関数でループ回数を設定
-------------------
>>> for i in range(5):
...     print(i)
...
0
1
2
3
4
-------------------


▲ループ後に後処理
-------------------
>>> for i in range(5):
...     print(i)
... else:
...     print("end")
...
0
1
2
3
4
end
-------------------


▲break文でループを抜ける場合の動作
-------------------
>>> for i in range(5):
...     if i == 2:
...         break
...     print(i)
... else:
...     print("end")
...
0
1
-------------------


▲continue文の使い方
-------------------
>>> for i in range(5):
...     if i % 2 == 1:
...         continue
...     print(i)
... else:
...     print("end")
...
0
2
4
end
-------------------


【6-4】
▲簡単なループ
-------------------
>>> num = 0
>>> while num < 3:
...     print("True")
...     num = num + 1
...
True
True
True
-------------------


▲else節付きのループ
-------------------
>>> num = 0
>>> while num % 2 == 0:
...     print("True")
...     num = num + 1
... else:
...     print("False")
...
True
False
-------------------


▲無限ループ
-------------------
>>> while True:
...     print("True")
...
True
True
 :
 :
-------------------


【6-5】
▲try文の書式
-------------------
>>> '2' + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
-------------------


▲単純な例外処理
-------------------
>>> try:
...     print(100 + 1)
... except:
...     print("error")
...
101
-------------------


▲else節，finally節を追加した例外処理
-------------------
>>> try:
...     print(100 + 1)
... except:
...     print("error")
... else:
...     print("end this process")
... finally:
...     print("last process")
...
101
end this process
last process
-------------------


▲例外発生時の流れ
-------------------
>>> print(100 + "abc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
-------------------

-------------------
>>> try:
...     print(100 + "abc")
... except:
...     print("error")
...
error
-------------------


▲特定のエラーだけを処理
-------------------
>>> try:
...     print(100 + "abc")
... except TypeError as E:
...     print("catch TypeError: ", E)
...
catch TypeError:  unsupported operand type(s) for +: 'int' and 'str'
-------------------


▲特定のエラー（複数）だけを処理
-------------------
>>> try:
...     print(100 + "abc")
... except (SyntaxError, TypeError) as E:
...     print("error: ", E)
...
error:  unsupported operand type(s) for +: 'int' and 'str'
-------------------

　
▲発生したエラーによって例外処理を分ける
-------------------
>>> try:
...     print(100 + "abc")
... except TypeError as E:
...     print("catch TypeError: ", E)
... except ZeroDivisionError as E:
...     print("catch ZeroDivisionError: ", E)
...
catch TypeError:  unsupported operand type(s) for +: 'int' and 'str'
-------------------