Pythonは親クラスを作成します
親クラスを作成する
どのクラスも親クラスになることができるため、構文は他のクラスを作成する場合と同じです。
例
Person
、with
firstname
、lastname
propertiesという名前のクラスと、printname
メソッドを作成します。
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()