Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Working with Instance and Class Variables | Introduction à la POO en Python
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
Programmation Orientée Objet en Python

bookChallenge: Working with Instance and Class Variables

Tâche

Swipe to start coding

Define a class named User with the following requirements:

  • Create a class variable total_users and initialize it to 0.
  • Implement the __init__ method to:
    • Take username as an argument.
    • Store username as an instance variable.
    • Increment total_users by 1 every time a new User instance is created.
  • Implement a method get_info that returns a tuple containing:
    • The user's name (the value of the instance variable for username).
    • The current value of total_users.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 7

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

bookChallenge: Working with Instance and Class Variables

Glissez pour afficher le menu

Tâche

Swipe to start coding

Define a class named User with the following requirements:

  • Create a class variable total_users and initialize it to 0.
  • Implement the __init__ method to:
    • Take username as an argument.
    • Store username as an instance variable.
    • Increment total_users by 1 every time a new User instance is created.
  • Implement a method get_info that returns a tuple containing:
    • The user's name (the value of the instance variable for username).
    • The current value of total_users.

Solution

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 7
some-alt