1.5つのコード
| 変数 | 値を入れる 変数は、値をしまう箱 | user “Sato” points = 120 print(user) print(points) 補足 = は代入 文字は””で囲む 数字はそのまま |
| if | 条件で分ける 条件が合えば、 その処理を実行 | coupon = True price = 3000 if coupon: print(“割引を適用”) 補足 if の後ろに条件を書く 条件がTrue なら実行 :のあとは字下げ |
| for | くり返す リストの中身を順番に取り出す | cart = [“りんご”。“牛乳”、“パン] for item in cart: print(item) 補足 forは順番に回す item に1つずつ入る リスト処理でよく使う |
| list/dict | まとめて持つ list: 順番つきで並べる dict: 名前を付け持つ | tasks = [“発注”,“検品”,“発送”] order ( ”id”: 101, ”status”: “paid” ) 補足: list は「並び」 dict は「キーと値」 どちらも超重要 |
| 関数 | 処理をまとめる 何度も使う処理は関数にする | def calc_total(price, shipping): return = price * shipping total = calc_total (2500, 500) print(total) 補足: def で関数を作る return で結果を返す 同じ処理を再利用しやすい |
