Error: the object does not have an attribute [closed]

1

I have the following code:

My problem is that the console output shows me an error that says:

  

AttributeError: type object 'Person' has no attribute 'say hello'   ()

Why does that happen and how can I solve it?

    
asked by Cristian Javier Blanco García 23.08.2018 в 05:21
source

2 answers

1

You have an indentation problem. The methods of a class must go "inside" of it. Try indenting:

class Persona:
    nombre = " "
    edad = 0
    pais = " "
    def saludar(self):
        print("Hola mi mombre es", self.nombre)
    def otroMetodo(self):
        ...
    
answered by 23.08.2018 / 05:36
source
0

Python uses the indentation a lot and you must take care of it, so that the Person class has the greeting method, you must place your code in the following way

class Persona:
    nombre = " "
    edad = 0
    pais = " "

    def saludar(self):
        print("Hola mi nombre es", self.nombre)

also with the other method

    
answered by 23.08.2018 в 22:16