Implementation
Code
We start to fill the Cat class:
- An attribute
namewith the predefined value'Kitty'; - A method
say_meow().
We create an object cat and call the say_meow() method.
12345678910class Cat: # An attribute name = 'Kitty' # A method def say_meow(self): print('Meow') # Instantiating an object cat = Cat() cat.say_meow()
Note
- Each method obligatory contains
self- a reference to the current object; - To call the method of the object, write
Object.Method().
Tâche
Swipe to start coding
- Add the
sleepmethod. - The
sleepmethod prints a message. - Instantiate an object using the
catvariable.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 3
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Awesome!
Completion rate improved to 7.69
Implementation
Glissez pour afficher le menu
Code
We start to fill the Cat class:
- An attribute
namewith the predefined value'Kitty'; - A method
say_meow().
We create an object cat and call the say_meow() method.
12345678910class Cat: # An attribute name = 'Kitty' # A method def say_meow(self): print('Meow') # Instantiating an object cat = Cat() cat.say_meow()
Note
- Each method obligatory contains
self- a reference to the current object; - To call the method of the object, write
Object.Method().
Tâche
Swipe to start coding
- Add the
sleepmethod. - The
sleepmethod prints a message. - Instantiate an object using the
catvariable.
Solution
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 3
single