Instance Variables in a class - the correct way?

In a class when creating an instance variable I was using this.

def __init__(self):
    self.hasTicket = False

and it works, then I came across @property decorator.
Which is the best method? Does it really matter.

def __init__(self):
    self._hasTicket = False


@property
def hasTicket(self):
     return self._hasTicket

@hasTicket.setter
def hasTicket(self, hasTicket):
     self._hasTicket = hasTicket

Ah, those aren’t really an alternative to self.hasTicket, it’s more to add a feature. Let’s say you want to let people do this:

x = Thingy()
x.hasTicket = True

BUT, you want to do some stuff whenever they do that. A good example would be if you were writing this to a database and that meant you needed to update the data whenever they set something in the object.

In that case you’d use @property so that you can run some code whenever the get or set that attribute. Otherwise it’s not very useful in Python since Python lets you just modify whatever you want anyway.