How do I declare an attribute in Python without a value?

In Python, and many other languages, there is a value that means “no value”. In Python, that value is None. So you could do something like this:

class User:
   username = None
   password = None

Those sure sound like instance variables though, and not class variables, so maybe do this:

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

Note how Python assigns the None value implicitly from time to time:

def f():
    pass
g = f() # g now has the value of None

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)