Python သည် Parent Class ကိုဖန်တီးပါ။
Parent Class တစ်ခု ဖန်တီးပါ။
မည်သည့်အတန်းမဆို parent class ဖြစ်နိုင်သည်၊ ထို့ကြောင့် syntax သည် အခြားသော class များကို ဖန်တီးခြင်းနှင့် အတူတူပင်ဖြစ်သည်-
ဥပမာ
Person
၊ with
firstname
နှင့် lastname
ဂုဏ်သတ္တိများ ၊ နှင့် printname
method ဟုခေါ်သော class တစ်ခုကို ဖန်တီးပါ ။
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname,
self.lastname)
#Use the Person class to create an object, and then
execute the printname method:
x = Person("John", "Doe")
x.printname()