Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Working with Instance and Class Variables | Introductie tot Python OOP
Practice
Projects
Quizzes & Challenges
Quizzen
Challenges
/
Objectgeoriënteerd Programmeren in Python

bookChallenge: Working with Instance and Class Variables

Taak

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.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 7

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

bookChallenge: Working with Instance and Class Variables

Veeg om het menu te tonen

Taak

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.

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 7
some-alt