Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Implementation | Classes and Objects
Object-Oriented Programming in Python

Glissez pour afficher le menu

book
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.

12345678910
class Cat: # An attribute name = 'Kitty' # A method def say_meow(self): print('Meow') # Instantiating an object cat = Cat() cat.say_meow()
copy

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

  1. Add the sleep method.
  2. The sleep method prints a message.
  3. Instantiate an object using the cat variable.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 3
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

Awesome!

Completion rate improved to 7.69

book
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.

12345678910
class Cat: # An attribute name = 'Kitty' # A method def say_meow(self): print('Meow') # Instantiating an object cat = Cat() cat.say_meow()
copy

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

  1. Add the sleep method.
  2. The sleep method prints a message.
  3. Instantiate an object using the cat variable.

Solution

Switch to desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

close

Awesome!

Completion rate improved to 7.69

Glissez pour afficher le menu

some-alt