← Courses

Python for AI — Beginner Foundations

Data Science

Classes · Lesson 45 of 76

Methods and attributes

Attributes are an object's data. Methods are functions that belong to the object and act on that data. Together they make an object that can do things, not just hold values.

Python

Notice every method takes self first — that's how it reaches its own object's attributes (self.balance).

Your turn: add a withdraw(self, amount) method that subtracts from the balance, then withdraw 100 and show the result.

You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →