[source code] Python Programming Tutorial - 30 - init

+1 Bucky Roberts · September 20, 2014
class Enemy:
   def __init__(self, x):
       self.energy = x

   def get_energy(self):
       print(self.energy)


jason = Enemy(5)
sandy = Enemy(9)

jason.get_energy()
sandy.get_energy()

Post a Reply

Replies

Oldest  Newest  Rating
0 Erkin Öner · September 26, 2014
I still didn't understand why we should use init or why its useful :ermm:
0 Wayne [Im That Damn Good] Leyden · September 24, 2014
So you use the init method when you need to pass arguments when creating new objects? or is there another way to do this?
  • 1

Python

107,287 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator