Metode __init__ bagian 1 - Contoh Kode Python
Metode __init__ bagian 1 - Contoh Kode Python
-------------------------------
class MenuItem:
def __init__(self):
print('Instance menu telah diciptakan')
def info(self):
return self.name + ': Rp.' + str(self.price) + '000'
def get_total_price(self, count):
total_harga = self.price * count
return total_harga
menu_item1 = MenuItem()
menu_item1.name = 'Roti Lapis'
menu_item1.price = 5
print(menu_item1.info())
result = menu_item1.get_total_price(4)
print('Hasil: ' + str(result))
-------------------------------
Baca:
3 Cara Menjadi Kaya Setelah Lulus Sekolah atau Kuliah
 Reviewed by sihat jok
        on 
        
September 21, 2020
 
        Rating:
 
        Reviewed by sihat jok
        on 
        
September 21, 2020
 
        Rating: 

 
 
 
Tidak ada komentar:
Posting Komentar