How to use static/helper method in a class?
<p>Below I have created a class. I am trying to use the method gcd(a,b) in the initialization of a Fraction object. However, when I was trying to do this it would not work WITHOUT the 'Fraction' part of "Fraction.gcd(a,b)". I used @staticmethod here, but it does absolutely nothing, i.e. my code works the same without it. </p>

<p>Is there anyway I can call gcd without putting "Fraction." in front of it. In Java I would normally create a static method and then just call it. I could very easily put the GCD code inside of the init, but I am trying to learn here!</p>

<p>I am missing a lot here. Can anyone explain: static methods, helper methods in a class and pretty much how I can use various methods inside of a class?</p>

<pre><code>class Fraction(object):
    def __init__(self, a, b):
        if( Fraction.gcd(a,b) &gt; 1):
            d = Fraction.gcd(a,b)
            self.num = a/d
            self.denom = b/d
        else:
            self.num = a
            self.denom = b

    @staticmethod    
    def gcd(a,b): 
        if a &gt; b: a,b = b,a
        while True:
            if b % a == 0: return a
            a, b = b%a, a

    def __repr__(self):
        return str(self.num) + "/" + str(self.denom)
</code></pre>
