Solve the error: AttributeError: 'Person' object has no attribute 'myfunc'

The error is shown in the figure below:

 1. First check the code and check whether there is any typo in the 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("Bill",63)
p1.myfunc()

 2. Check indentation, punctuation, etc.

 3. It is found that the two indents are not the same and are not aligned. Try changing them to alignment

 4. Run it after changing it to alignment, and it runs successfully

 Hope to help you, thank you~

Guess you like

Origin blog.csdn.net/Along_168163/article/details/131579941