day11
・名前は狭い範囲のワードを使うこと
・動詞を必ず前に置くこと
def fetch_latest_news(): ... def calc_tax_including(price): ... def aggregate_sum_price(items): ...
is_ , has_ ,で始まる変数名はBoolを返すようにする
def is_valid(sth) return not name.startswith("tttsssss")
意味のまとまりで関数を作ること。
import csv def read_csv(): """ some sentences """ with open(...) as f : reader = csv.reader(f) for row in reader: name = row[0] price = int(row[0]) yield name, price def is_add_price(price): return price < 90000 def main(): products = read.products() for name, price in products: if is_add_price(price) print(name)
・yield とは..........関数を一時的に実行停止させることが出来るもの。下に書いてあるからわからなくなったら読む
【Python入門】yield文の基本的な使い方を解説 | 侍エンジニアブログ