Lesson 32 of 34

Methods: Objects-ന് എന്ത് ചെയ്യാനാകും

10 min 35 XP

Class-നുള്ളിൽ എഴുതുന്ന functions-നെ methods എന്ന് വിളിക്കുന്നു. അവയുടെ ആദ്യ parameter എപ്പോഴും self ആണ്. Method-ന് object-ന്റെ data വായിക്കാനും മാറ്റാനും കഴിയും.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

__str__ method ഉണ്ടെങ്കിൽ print(object) സൗഹൃദപരമായ ടെക്സ്റ്റ് കാണിക്കും.

Example: edit me and press Run

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.

Challenge

+35 XP

ഒരു BankAccount class എഴുതൂ: • __init__: balance = 0-ൽ തുടങ്ങുന്നു • deposit(amount): balance-ലേക്ക് കൂട്ടുന്നു • withdraw(amount): മതിയായതുണ്ടെങ്കിൽ കുറയ്ക്കുന്നു, അല്ലെങ്കിൽ "Insufficient balance" print ചെയ്യുന്നു • get_balance(): balance തിരികെ നൽകുന്നു

Output Loading Python (first time takes a few seconds)
Press Run to see the result here.