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().
Compito
Swipe to start coding
- Add the
sleepmethod. - The
sleepmethod prints a message. - Instantiate an object using the
catvariable.
Soluzione
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 1. Capitolo 3
single
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Suggested prompts:
Riassuma questo capitolo
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 7.69
Implementation
Scorri per mostrare il 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().
Compito
Swipe to start coding
- Add the
sleepmethod. - The
sleepmethod prints a message. - Instantiate an object using the
catvariable.
Soluzione
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 1. Capitolo 3
single