Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Working with Instance and Class Variables | Introducción a la POO en Python
Practice
Projects
Quizzes & Challenges
Cuestionarios
Challenges
/
Programación Orientada a Objetos en Python

bookChallenge: Working with Instance and Class Variables

Tarea

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.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 7

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

bookChallenge: Working with Instance and Class Variables

Desliza para mostrar el menú

Tarea

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.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 7
some-alt