Get the return in a function in other function?
<p>Is there any way to access to the return in a function inside other function ?</p>

<p>Probably the next code explain more what I want to do.</p>

<pre><code>class perro:
    def coqueta(self, num1, num2):
        self.num1 = num1
        self.num2 = num2
        return self.num1 + self.num2

    def otro_perro(self, coqueta):
        print otro_perro




mascota = perro()
ejemplo = mascota.coqueta(5,5)
mascota.otro_perro()

print ejemplo 
</code></pre>

<p>How can i get the return of the first <code>def</code> (<code>coqueta</code>) to print in the second function (<code>otro_perro</code>)?</p>

<p>Just make it an attribute of the <code>perro</code> class. Thats really the whole point of class, to modularize, organize, and encapsulate your data instead of having to use <code>global</code>s everywhere:</p>

<pre><code>class perro:
    def coqueta(self, num1, num2):
        self.num1 = num1
        self.num2 = num2
        self._otro_perro = self.num1 + self.num2

    def otro_perro(self):
        print self._otro_perro




mascota = perro()
mascota.coqueta(5,5)
mascota.otro_perro() # will print the value of self._orto_perro
</code></pre>

<p>I added the extra underscore before <code>orto_perro</code> because you had already used that name for your method. And as a unrelated side note, class names a gereral capitalized in Python. So <code>perro</code> would become <code>Perro</code>.</p>

python function