Python class Point.draw() not working

I’m getting this error: AttributeError: ‘NoneType’ object has no attribute ‘draw’

Can anyone explain why I am seeing this error? Thanks.

My code is below:
class Point:

def __init__(self, x, y):

    self.x = x

    self.y = y

@classmethod

def defaults(cls):

    cls(1, 2)

def draw(self):

    print(f"Point ({self.x}, {self.y})")

robert = Point.defaults()

robert.draw()

fix your code you have forgot to use return keyword

@classmethod
def defaults(cls):
return cls(1, 2)

1 Like