How can I make use of my class?


I am learning python from minimal knowledge. I’ve had no difficulty until I reached the classes section. And I am highly confused by them.
In the following example:

class Rules():
  def washing_brushes(self):
    return "Point bristles towards the basin while washing your brushes."
rule_1 = Rules()

This is what prints:
<bound method Rules.washing_brushes of <main.Rules object at 0x7fb5173814e0>>

I realize that it is showing me the location of this object on the computer, and the object is defined by this class. But how can I make use of the object, or even the class for that matter? Like say… use the variables in the class or define parameters for a variable and pass it through the class to change it and then get it back and actually use it? I’ve searched for a couple of hours for information and am coming up short. Can someone explain how to make use of a class, and even better, give an example?

And this:

class Circle:
  pi = 3.14
  def __init__(self, diameter):
    print("New circle with diameter: {diameter}".format(diameter=diameter))
  def get_area(self):
    print(((self/2)^2)* Circle.pi)
teaching_table = Circle(36)

prints: New circle with diameter: 36
Traceback (most recent call last):
File “”, line 12, in
File “”, line 9, in get_area
print(((self/2)^2)* Circle.pi)
TypeError: unsupported operand type(s) for /: ‘Circle’ and ‘int’

Isn’t self an “int” at this point (defined by Circle(36)? So why can’t I use it?
Sorry if my questions are ambiguous. I’m getting discouraged.


I think maybe I figured it out…
In part 1:
changing it to:
appears to output what I’m looking for.

and in part 2:
it should be self.pi, but I still can’t use the operands on it…


methods, just like function require parentheses when called, which you do correctly here:


yet for some reason, you don’t do it when calling washing_brushes.

no, self refers to the current instance. If you have multiple instances:

teaching_table = Circle(36)
teaching_table_2 = Circle(37)

and you would call get_area on other instances, self is there to help you on which instance the method is called.