[Python] Python Class __init__ Confirmation

Discussão em 'Python' iniciado por Stack, Agosto 7, 2025.

  1. Stack

    Stack Membro Participativo

    Im trying to understand Python Classes. I am a little confused around defining the __init__. If I have 4 functions created all taking various input variables. Do I have to assign each variable in the __init__?

    class Thing:
    def __init__(self, arguments, name, address, phone_number, other):
    self.arguments = arguments
    self.name = name
    self.address = address
    self.phone_number = phone_number
    self.other = other

    def First(self, name):
    print self.name

    def Arguments(self, arguments):
    print self.arguments

    def Address(self, address, phone_number):
    print self.address + str(self.phone_number)

    def Other(self, other):
    print self.other


    The above is completely made up so please excuse its pointlessness (arguably its point is to illustrate my question so guess its not pointless).

    No doubt im going to get loads of down marks for this question for some reason but I have been reading various books (Learning Python The Hard Way, Python For Beginners) and been reading various tutorials online but none of them actually confirm "You must add every variable in the init function". So any help understanding the __init__ a little better would be appreciated.

    Continue reading...

Compartilhe esta Página