#Here's my code:

class Person:

def _init_(self, name, age):
self.name = name
self.age = age

def myfunc(self):
print("Hello my name is " + self.name)

p1 = Person("Kate", 18)

#Here's my outcome:

Hello my name is Kate 

Why is there 'None' after my sentence?


1 Answer 1


myfunc() does not have a return statement. In this case python defaults to returning None.

print( p1.myfunc() ) executes myfunc() which prints "Hello my name is Kate", then it prints the return value of myfunc(), which is None.

Since myfunc() already executes print() to display what you want, you only need to call it with p1.myfunc(), there is no need to print( p1.myfunc() ).


Not the answer you're looking for? Browse other questions tagged or ask your own question.