x is local to the method, that is, it should not (and cannot, at least not easily) be accessed from outside. Worse - it exists only when the method starts (and is deleted after it is returned).
Note that you can assign an attribute to a method (for any function):
class Leaf(object): def green(self): ... green.x = 100 print Leaf.green.x
But this is probably not what you want (for starters, you cannot access it as a local variable inside the method - because it is not one) and actually very rarely useful (unless you have a really good reason, for, it's just use class).
source share