Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person:
- def __init__(self, name, age):
- self.name = name
- self.age = age
- def displayPerson(self):
- print(self.name, '-', self.age)
- class Student(Person):
- def __init__(self, name, age, univer, grant):
- super().__init__(name, age)
- self.univer = univer
- self.grant = grant
- def displayStudent(self):
- if self.grant:
- print(self.name, '-', self.age, 'studies at:', self.univer, ' and has grant')
- else:
- print(self.name, '-', self.age, 'studies at:', self.univer, " and hasn't grant")
- def setGrant(self, grant): # Установщик гранта, есть он или нет
- self.grant = grant
- vlad = Person('Vlad', 26)
- Person.displayPerson(vlad) # Вызывай как хочешь
- vlad.displayPerson() # Вызывай как хочешь
- igor = Student('Igor', 23, 'SPBGMTU', True)
- Student.displayStudent(igor) # Вызывай как хочешь
- igor.displayStudent() # Вызывай как хочешь
- igor.setGrant(False) # Присваиваем grant = false
- igor.displayStudent()
- #================================================================
- class Mammal(object):
- def __init__(self, mammalName):
- # self.mammalName = mammalName # НИХУЯ НЕ ИЗМЕНИТСЯ
- print(mammalName, 'is a warm-blooded animal.')
- class Dog(Mammal):
- def __init__(self):
- print('Dog has four legs.')
- super().__init__('Dog')
- d1 = Dog()
- #================================================================
- class Mammal(object): # Mammal - млекопитающие
- def __init__(self, mammalName):
- print(mammalName, 'is a warm-blooded animal.')
- class Dog(Mammal):
- def __init__(self, mammalName):
- print('Dog has four legs.')
- super().__init__(mammalName)
- print('=' * 20)
- d1 = Dog("KEK")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement