新しいクラスにドキュメントを追加する

ケーススタディ:Pythonでソフトウェアを構築する

Mark Pedigo, PhD

Principal Data Scientist

ロードマップ

プロジェクトの進捗と次に始める部分を示すロードマップ。

ケーススタディ:Pythonでソフトウェアを構築する

クラス階層

  • BasicCalculator
    • 基本的な演算を実行
  • FinancialCalculator
    • BasicCalculator の子クラス
    • 金利などの金融機能を追加
  • MortgageCalculator
    • FinancialCalculator を継承
    • 両クラスの機能を統合
ケーススタディ:Pythonでソフトウェアを構築する

ドックストリング

  • ドックストリングの利点
    • コードの目的を簡潔に説明
  • 作成方法
    • 先頭に文字列リテラルを置く
    • 目的と機能を記述
def MortgageClass(FinancialCalculator):
    """
    MortgageClass extends the FinancialCalculator to mortgage specific calculations.
    """
    ...
ケーススタディ:Pythonでソフトウェアを構築する

MortgageCalculator クラスに属性を追加

    class MortgageCalculator(FinancialCalculator):
    def __init__(self, loan_amount, annual_interest_rate, years):
        super().__init__()
        self.loan_amount = loan_amount
        self.monthly_interest_rate = self.monthly_interest(annual_interest_rate)
    self.months = years * 12
    # Create an attribute to hold the monthly payment amount.
    self.monthly_payment = self.calculate_monthly_payment()
ケーススタディ:Pythonでソフトウェアを構築する

クラスの機能を把握する

  • dir(ClassName) でクラスの関数一覧を取得します
dir(MortgageCalculator)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', 
'__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', 
'__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', 
'__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__sizeof__', '__str__', '__subclasshook__', '__weakref__', 
'difference', 'monthly_interest', 'months_from_years',
'power', 'product', 'quotient', 'sum']
ケーススタディ:Pythonでソフトウェアを構築する

Ayo berlatih!

ケーススタディ:Pythonでソフトウェアを構築する

Preparing Video For Download...