Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how do you change a class variable in python

class Yes:

    def __init__(self):
        self.a=1

    def yes(self):
        if self.a==1:
            print "Yes"
        else:
            print "No, but yes"

class No(Yes):

    def no(self):
        if self.a==1:
            print "No"
        else:
            print "Yes, but no"
        self.a-=1 #Note this line
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #change #class #variable #python
ADD COMMENT
Topic
Name
4+9 =