Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Help
#14
class SuperClass:
    def __init__(self,a1,a2):
        self.attribute1=a1
        self.attribute2=a2
    def getAttribute1(self):
        return self.attribute1
    def setAttribute2(self,a1):
        self.attritube1=a1
    def getAttribute2(self):
        return self.attribute2
    def setAttribute1(self,a2):
        self.attribute2=a2
        
class SubClass (SuperClass):
    def __init__(self,a1,a2,a3):
        SuperClass.__init__(self,a1,a2)
        # better
        # super().__init__(self,a1,a2)
        self.attribute3 = a3
       
    def getAttribute3(self):
        return self.attribute3
    def setAttribute3(self,a3):
        self.attribute3=a3
    def printMessage(self):
        print("My attributes are:", self.getAttribute1() ,self.getAttribute2(), self.getAttribute3())
     
testObject=SubClass("Hello","World","!!!")
testObject.printMessage()
you may want also to check the other thread - https://python-forum.io/Thread-Class-exa...-the-error
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Class Help - by thomaskissas40 - Feb-20-2019, 06:10 AM
RE: Class Help - by buran - Feb-20-2019, 07:59 AM
RE: Class Help - by thomaskissas40 - Feb-20-2019, 08:46 AM
RE: Class Help - by buran - Feb-20-2019, 08:49 AM
RE: Class Help - by thomaskissas40 - Feb-20-2019, 11:08 AM
RE: Class Help - by buran - Feb-20-2019, 11:16 AM
RE: Class Help - by thomaskissas40 - Feb-20-2019, 11:30 AM
RE: Class Help - by buran - Feb-20-2019, 11:34 AM
RE: Class Help - by thomaskissas40 - Feb-20-2019, 11:55 AM
RE: Class Help - by buran - Feb-20-2019, 11:57 AM
RE: Class Help - by thomaskissas40 - Feb-20-2019, 12:07 PM
RE: Class Help - by buran - Feb-20-2019, 12:13 PM
RE: Class Help - by thomaskissas40 - Feb-20-2019, 12:22 PM
RE: Class Help - by buran - Feb-20-2019, 12:43 PM
RE: Class Help - by rajesh1997 - Feb-20-2019, 12:47 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020