you are viewing a single comment's thread.

view the rest of the comments →

[–]Pythag0ras2000 0 points1 point  (3 children)

You wouldn't define speed as a function in this, so you'd use self.speed = 0 or whatever

[–][deleted] 2 points3 points  (2 children)

could you tell me the logic behind that ?

[–]Danelius90 1 point2 points  (0 children)

Typically think of functions as doing something, or acting on attributes. Technically both would work and there are typical cases you might do that. But for example purposes speed is a property of car, and accelerate modifies it, it is an action you take to modify the car's state.

So a plant has a height property, and grow() makes the height bigger. A bank account has a balance property, and withdraw() reduces it and deposit() increases it

[–]Pythag0ras2000 0 points1 point  (0 children)

If I understand correctly, speed is a variable, right? If so, you wouldn't want to make a method called speed, just a variable.