PYTHON CORE · LESSON 49
Name for each object
Method of __init__ · about 15 minutes
Learning with progressRead the summary for free. To save the work, log in to the account.
Type the code yourself
Dial class and object. Check the two indentation levels.
class Dog:
def __init__(self, name):
self.name = name
pet = Dog("Рекс")
print(pet.name)Open the editor for class workSolve it yourself
Create Cat with __init__(self, name), which saves name to self.name. Create a pet with the name «Мур» and output its name.
The answer is hidden. Use similar examples from the lesson notes.
Opening up your homework