class Point4D(object):
def __init__(self,w, x, y, z):
self.w = w
self.x = x
self.y = y
self.z = z
def __str__(self):
print('{}, {}, {}, {}'.format(self.w, self.x, self.y, self.z))
my_4d_point = Point4D(1, 2, 3, 1)
print(my_4d_point)
I get the output 1 2 3 1 , but i keep getting the error
TypeError: __str__ returned non-string (type NoneType) in line 12.
Why?
Use
return
. The error is because you print, but return nothing.