Presta atención ya que en esta crónica hallarás el arreglo que buscas.
Ejemplo 1: herencia en python
# =============================================================================# Inhertance# =============================================================================classA:deffeature1(self):print('Feature 1 in process...')deffeature2(self):print('Feature 2 in process...')#Pt.1classB:deffeature3(self):print('Feature 3 in process...')deffeature4(self):print('Feature 4 in process...')
a1 = A()
a1.feature1()
a1.feature2()
a2 = B()
a2.feature3()
a2.feature4()# THE ABOVE PROGRAM IS A PROGRAM WITHOUT USING INHERITANCE# WITH THE USE OF INHERITANCE IS BELOWclassA:deffeature1(self):print('Feature 1 in process...')deffeature2(self):print('Feature 2 in process...')classB(A):deffeature3(self):print('Feature 3 in process...')# Pt.2deffeature4(self):print('Feature 4 in process...')
a1 = A()
a1.feature1()
a1.feature2()
a2 = B()
a2.feature3()
a2.feature4()
Ejemplo 2: como heredar una clase en python
classBird():defeat(self):print("eating")classSparrow(Bird):defsound(self):print("ChiChi!")
birdobj = Sparrow()
birdobj.eat()
birdobj.sound()
Nos puedes añadir valor a nuestro contenido informacional participando con tu veteranía en las notas.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)