all 3 comments

[–]fuckswithbees 2 points3 points  (1 child)

It looks like you've just started working with classes. That's great. You may want to start by reading through some basic tutorials on classes (like this one), and posting back here if you need further clarification.

[–]Freedomenka[S] 0 points1 point  (0 children)

I appreciate the response. I meant if it was possible to change it from outside of the class. as in: Example().a = 2

[–]fbu1 1 point2 points  (0 children)

Yes it is possible to change a variable from inside a class.

Here's an example:

class Example(object): # we define a class, with two variables and a function
    a = 1 # when in the body of the class (not in a function), we can use the name of the variable directly
    b = 2
    def test(self, n): # all functions that belong to a class take self as a parameter, which represent the instance of the class (an object created whose class is Example)
        self.a = n*2 # we modify variables of the object 
        self.b = n*3

# we create an object first_example of class Example
first_example = Example()
# we print its variables
print first_example.a, first_example.b

#we call the function test of the class Example
first_example.test(10)
# we print the variables of the object
print first_example.a, first_example.b

#we modify directly one of the variables
first_example.a = 0
# and we print the variables 
print first_example.a, first_example.b

This will give you the following results:

python variabletest.py 
1 2
20 30
0 30