अपनी नई class का डॉक्यूमेंटेशन

केस स्टडी: Python में सॉफ्टवेयर बनाना

Mark Pedigo, PhD

Principal Data Scientist

Roadmap

रोडमैप जो दिखाता है कि प्रोजेक्ट के कौन-से हिस्से पूरे हो गए हैं और अब क्या शुरू होगा.

केस स्टडी: Python में सॉफ्टवेयर बनाना

आपकी Class Hierarchy

  • BasicCalculator
    • बेसिक अंकगणित करता है
  • FinancialCalculator
    • BasicCalculator का child
    • ब्याज दर जैसी वित्तीय सुविधाएँ जोड़ता है
  • MortgageCalculator
    • FinancialCalculator से इनहेरिट करता है
    • दोनों classes की कार्यक्षमता जोड़ता है
केस स्टडी: Python में सॉफ्टवेयर बनाना

Docstrings

  • Docstrings के फायदे
    • कोड की स्पष्ट, संक्षिप्त व्याख्या देता है
  • Docstring कैसे बनाएँ
    • पहला स्टेटमेंट एक string literal रखें
    • उद्देश्य और कार्यक्षमता समझाएँ
def MortgageClass(FinancialCalculator):
    """
    MortgageClass extends the FinancialCalculator to mortgage specific calculations.
    """
    ...
केस स्टडी: Python में सॉफ्टवेयर बनाना

Mortgage Calculator class में attributes जोड़ें

    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 में सॉफ्टवेयर बनाना

Classes की कार्यक्षमता ट्रैक करें

  • किसी class के functions की सूची पाने के लिए 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 में सॉफ्टवेयर बनाना

अभ्यास करते हैं!

केस स्टडी: Python में सॉफ्टवेयर बनाना

Preparing Video For Download...