I'm new to python and I've been trying to understand classes.
As far as I know, when you create a class, you must insert self before a variable, so that self is replaced by the instances, when they're created (these become instance attributes). Besides instance attributes, there are also class attributes, which are defined at the top of the class, before any methods.
However, I came across this code:
class Hero:
def __init__(self, name):
self.name = name
self.health = 100
def eat(self, food):
if food == 'apple':
health += 20
elif food == "chocolate":
health -= 10
Why doesn't food have self before it? It is not an instance attribute but it doesn't seem to me that it is a class attr either.. I'm using python 2.X