Class error in Python

Asked

Viewed 134 times

0

I created the code below but it’s giving me error:

Pessoa = Empregados('joao')
TypeError: Empregados() takes no arguments.

What I might have done wrong?

class Empregados:
    def __int__(self, nome, email, skype):
        self.nome = str(nome)
        self.email = str(email)
        self.skype = str(skype)

    def mostrar(self):
        print(self.nome, self.email, self.skype)
empr = Empregados('Joao', '[email protected]', 'Joao.vitor')
empr.mostrar()
  • 1

    The name of the method is __init__, and not __int__. Anyway, just do it Empregados('joao') will also give error because you also need to pass email and skype

  • I got it, it worked, thank you very much.

1 answer

3

Correct the class initialization method name, the correct is __init__

class Empregados:
    def __init__(self, nome, email, skype):
        self.nome = str(nome)
        self.email = str(email)
        self.skype = str(skype)

to call the class the correct one is so:

variavel = Classe(atributo='valor')

in your case:

pessoa = Empregados(nome='joao', email='[email protected]', skype='joao')

Another tip:

you do not need to use str if email, name and skype already comes as string ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.