Challenge: Working with Instance and Class Variables
Uppgift
Swipe to start coding
Define a class named User with the following requirements:
- Create a class variable
total_usersand initialize it to0. - Implement the
__init__method to:- Take
usernameas an argument. - Store
usernameas an instance variable. - Increment
total_usersby1every time a newUserinstance is created.
- Take
- Implement a method
get_infothat returns a tuple containing:- The user's name (the value of the instance variable for username).
- The current value of
total_users.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 7
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Fantastiskt!
Completion betyg förbättrat till 3.85
Challenge: Working with Instance and Class Variables
Svep för att visa menyn
Uppgift
Swipe to start coding
Define a class named User with the following requirements:
- Create a class variable
total_usersand initialize it to0. - Implement the
__init__method to:- Take
usernameas an argument. - Store
usernameas an instance variable. - Increment
total_usersby1every time a newUserinstance is created.
- Take
- Implement a method
get_infothat returns a tuple containing:- The user's name (the value of the instance variable for username).
- The current value of
total_users.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 7