Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Challenge: User | OOP Concepts
In-Depth Python OOP

book
Challenge: User

Compito

Swipe to start coding

  1. Define the User class by the class keyword.
  2. The User class should have the __init__ method that takes 3 arguments:
    self - an instance of the class.
    username - user's username.
    password - user's password.
  3. The __init__ method should assign arguments to the instance attributes via the self keyword.
  4. Create the bob instance of the User class with any username and password.

Once you've completed this task, click the button below the code to check your solution.

Soluzione

class User:
def __init__(self, username, password):
self.username = username
self.password = password


bob = User("bob.user", "bob123456")
john = User("john123top", "j123j321")

print(bob.username, bob.password)
print(john.username, john.password)

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 5
___ User:
def __init__(self, ___, ___):
self.___ = username
self.password = ___


bob = User(___, ___)
john = User("john123top", "j123j321")

print(bob.username, bob.password)
print(john.username, john.password)
toggle bottom row
some-alt