Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: Working with Instance and Class Variables | Introduzione alla OOP in Python
Practice
Projects
Quizzes & Challenges
Quiz
Challenges
/
Programmazione Orientata Agli Oggetti in Python

bookChallenge: Working with Instance and Class Variables

Compito

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.

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 7

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

bookChallenge: Working with Instance and Class Variables

Scorri per mostrare il menu

Compito

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.

Soluzione

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 7
some-alt