Pythonで親クラスと子クラスを使って親子関係を表現し、これを実装してみます。 ■今回の環境(Python) 今回のPythonは、バージョン3.9.16を用いる。(なお、Google Colaboratory(Google Colab)を使用。) ■親クラスと子クラスを定義する では、早速親クラスと子クラスを定義するために、コードを書いていきます。 ■コード class Parent: def __init__(self, name): self.name = name def greet(self): print(f"私の名前は {self.name}") class Child(Parent): def __init__(self, name, age): super().__init__(name) self.age = age def introduce(self): prin
![Pythonで親クラスと子クラスを使って親子関係を表現する](https://cdn-ak-scissors.b.st-hatena.com/image/square/b0e6c97966e87a40b9ffc727d8131acbff631a61/height=288;version=1;width=512/https%3A%2F%2Flaboratory.kazuuu.net%2Fwp-content%2Fuploads%2F2021%2F07%2FL.png)