I have two questions regarding this piece of code:
class Enemy
def __init__ (self, x):
self.energy=x
jason=Enemy(5)
Why do I have to use
selfwhen I create functions and instance variables? What is the purpose of using it?When we create the
jasonobject, we assign it a life of5, asEnemy(5). However, can class names take variables inside? Or is it the__init__function which makes it possible? (I'd expect something like,class Enemy (x), when we declare the class).