Implementation
Code
We start to fill the Cat
class:
- An attribute
name
with 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()
.
Taak
Swipe to start coding
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 3
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 7.69
Implementation
Veeg om het menu te tonen
Code
We start to fill the Cat
class:
- An attribute
name
with 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()
.
Taak
Swipe to start coding
- Add the
sleep
method. - The
sleep
method prints a message. - Instantiate an object using the
cat
variable.
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Awesome!
Completion rate improved to 7.69Sectie 1. Hoofdstuk 3
single