<jupyter_start><jupyter_text>PERTEMUAN 3 Inheritanceinheritance adalah konsep pemrograman dimana class induk dapat menurunkan / mewariskan atribut dan method sepenuhnya kepada subclass (kelas anak)fungsi dari konsep inheritance adalah mencegah duplikasi(penggandaan) program agar penulisan program tidak diulang. Contoh peulisan inheriance> class mahasiswa(Dosen):contoh di atas menunjukkan bahwa kelas mahasiswa merupakan anak dari kelas Dosen  Pendeklarasian kelas induk<jupyter_code>class user:
    def __init__(self,name):
        self.name = name
        
    def print_name(self):
        print("Name :",self.name)<jupyter_output><empty_output><jupyter_text>Contoh pendeklarasian kelas anak (subclass)<jupyter_code>class programmer(user):
    def __init__(self,name):
        self.name = name
        
    def doPython(self):
        print("Programmin Python")<jupyter_output><empty_output><jupyter_text>Contoh program dari inheritance<jupyter_code>class user:
    def __init__(self,name):
        self.name = name
        
    def print_name(self):
        print("Name :",self.name)

class programmer(user):
    def __init__(self,name):
        self.name = name
        
    def doPython(self):
        print("Programmin Python")
        
brian1 = user("brian")
brian1.print_name()
print()
diana = programmer("diana")
diana.print_name()
diana.doPython()<jupyter_output>Name : brian

Name : diana
Programmin Python<jupyter_text>contoh dari program di atas adalah kelas user mewariskan kepada kelas programmer, tetapi subclass programmer tidak bisa mengakses/mengambil atribut dari kelas user yang di sebabkan karena subclass programmer tidak mendeklarasikan atribut dari induk kelasnya<jupyter_code>class Fish:
    def __init__(self,first_name,last_name="Fish",skelaton="bone",eyelids=False):
        self.first_name = first_name
        self.last_name = last_name
        self.skelaton = skelaton
        self.eyelids = eyelids
        
    def swim(self):
        print("The fish is swimming")
        
    def swim_backwards(self):
        print("The fish can swim backwards")
        
class Trout(Fish):
    pass

terry = Trout("Terry")
print(terry.first_name+""+terry.last_name)
print(terry.skelaton)
print(terry.eyelids)
terry.swim()
terry.swim_backwards()<jupyter_output>TerryFish
bone
False
The fish is swimming
The fish can swim backwards<jupyter_text>Program diatas adalah kelas Trout meng copy / mewarisi keseluruhan aktifitas dari kelas Fish, namun kelas Fish tidak bisa mengakses atribut dan method dari kelas Trout dikarenakan dia merupakan induk kelasnya.<jupyter_code>class Fish:
    def __init__(self,first_name,last_name="Fish",skelaton="bone",eyelids=False):
        self.first_name = first_name
        self.last_name = last_name
        self.skelaton = skelaton
        self.eyelids = eyelids
        
    def swim(self):
        print("The fish is swimming")
        
    def swim_backwards(self):
        print("The fish can swim backwards")
        
class Clownfish(Fish):
    def live_with_anemone(self):
        print("The clownfish is coexiting with sea anemone.")
        
casey = Clownfish("Casey")
print(casey.first_name+""+casey.last_name)
casey.swim()
casey.live_with_anemone()<jupyter_output>CaseyFish
The fish is swimming
The clownfish is coexiting with sea anemone.
{'fraction_non_alphanumeric': 0.08318209316394434, 'fraction_numerical': 0.0009074410163339383, 'mean_word_length': 3.980421686746988, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '635137', 'license': 'MIT', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1131, 'n_words': 266, 'path': 'pertemuan3.ipynb', 'repo_name': 'Muzammil12345/Catatan-Materi-PBO', 'size': '3306'}