Why does 'None' get printed when I call this class?


A Methodical Approach

Why does this code:

class Animal(object):
  is_alive = True
  def __init__(self, name, age):
    self.name = name
    self.age = age
  def description(self):
  	print self.name
   	print self.age
hippo = Animal('Jolly', 20)
print hippo.description() 

print None like this:



functions and methods return None by default, given your description doesn’t have a return keyword, None is returned, and given you have a print statement in front of the method call, the returned result is printed


So in this example, the function description() returns None. Is there a way to change what this returns or not print None? When I add a return underneath it says there is an indentation error.


well the print statement in front of the method call causes the returned result by the method to be printed


Obviously. Not sure how I missed that. Thanks!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.