Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Working with Instance and Class Variables | Introdução à OOP em Python
Practice
Projects
Quizzes & Challenges
Questionários
Challenges
/
Programação Orientada a Objetos em Python

bookChallenge: Working with Instance and Class Variables

Tarefa

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.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 7

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookChallenge: Working with Instance and Class Variables

Deslize para mostrar o menu

Tarefa

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.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 7
some-alt