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


#1

A Methodical Approach
https://www.codecademy.com/courses/learn-python/lessons/introduction-to-classes/exercises/a-methodical-approach?action=lesson_resume

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:

Jolly
20
None

#2

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


#3

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.


#4

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


#5

Obviously. Not sure how I missed that. Thanks!


#6

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