Calling methods from classes
<p>I'm writing some classes:</p>

<pre><code>bean_version = "1.0"
from random import randint
console = []
print "Running Bean v%s" % bean_version
#Math Function
class math(object):
    def __init__(self, op1 = 0, op2 = 0):
        self.op1 = op1
        self.op2 = op2
    def add(self):
        return self.op1 + self.op2
    def sub(self):
        return self.op1 - self.op2
    def mul(self):
        return self.op1 * self.op2
    def div(self):
        return self.op1 / self.op2
</code></pre>

<p>What I realized I could do is:</p>

<pre><code>math.add(math(3,5))
==&gt;8
</code></pre>

<p>What I'm wondering is, is there any way to be able to do:</p>

<pre><code>math.add(3,5)
</code></pre>

<p>Python 2.7.10</p>

<p>That is possible. In this case you use the class just as a way to logically group your operators (add, sub, mul, div) and you don't really need to initialize the operands in the class instance itself. This calls for the <a href="https://docs.python.org/2/library/functions.html#staticmethod" rel="nofollow"><code>staticmethods</code></a> decorator, and the code looks like the one below.
You can also see it in action here: <a href="https://eval.in/639864" rel="nofollow">https://eval.in/639864</a></p>

<pre><code>bean_version = "1.0"
from random import randint
console = []
print "Running Bean v%s" % bean_version
#Math Function
class math(object):
    def __init__(self):
        pass
    @staticmethod
    def add(op1, op2):
        return op1 + op2
    @staticmethod
    def sub(op1, op2):
        return op1 - op2
    @staticmethod
    def mul(op1, op2):
        return op1 * op2
    @staticmethod
    def div(op1, op2):
        return op1 / op2

print math.add(3,5)
print math.sub(3,5)
print math.mul(3,5)
print math.div(3,5)
</code></pre>

python python-2.7