Skip to content

Multiple instances of a Class in Python

Lets start again with our example Animal class:

class Animal(object):

	def speak(self):
		print "I don’t know how to speak"
	
	def walk(self):
		print "I don’t know how to walk"
	
	def breath(self):
                print "I don’t know how to breath"

Previously we have created a new instance of this class in the ‘tiger’ variable, but we can also create more instances, as classes are designed to be reusable:

tiger = Animal()
bear = Animal()
fish = Animal()

And we call each method in the Animal class from the new instance variables:

tiger.speak()
bear.walk()
fish.breath()
Output:
I don’t know how to speak
I don’t know how to walk
I don’t know how to breath
Published inPyCharmPythonscripting