title: Python SyntaxError :'return' outside function
body: <p>Compiler showed:</p>
  
  <pre><code>File "temp.py", line 56
      return result
  SyntaxError: 'return' outside function
  </code></pre>
  
  <p>Where was I wrong?</p>
  
  <pre><code>class Complex (object):
      def __init__(self, realPart, imagPart):
          self.realPart = realPart
          self.imagPart = imagPart            
  
      def __str__(self):
          if type(self.realPart) == int and type(self.imagPart) == int:
              if self.imagPart &gt;=0:
                  return '%d+%di'%(self.realPart, self.imagPart)
              elif self.imagPart &lt;0:
                  return '%d%di'%(self.realPart, self.imagPart)   
      else:
          if self.imagPart &gt;=0:
                  return '%f+%fi'%(self.realPart, self.imagPart)
              elif self.imagPart &lt;0:
                  return '%f%fi'%(self.realPart, self.imagPart)
  
          def __div__(self, other):
              r1 = self.realPart
              i1 = self.imagPart
              r2 = other.realPart
              i2 = other.imagPart
              resultR = float(float(r1*r2+i1*i2)/float(r2*r2+i2*i2))
              resultI = float(float(r2*i1-r1*i2)/float(r2*r2+i2*i2))
              result = Complex(resultR, resultI)
              return result
  
  c1 = Complex(2,3)
  c2 = Complex(1,4)
  print c1/c2
  </code></pre>
  
  <p>What about this?</p>
  
  <pre><code>class Complex (object):
      def __init__(self, realPart, imagPart):
          self.realPart = realPart
          self.imagPart = imagPart            
  
      def __str__(self):
          if type(self.realPart) == int and type(self.imagPart) == int:
              if self.imagPart &gt;=0:
                  return '%d+%di'%(self.realPart, self.imagPart)
              elif self.imagPart &lt;0:
                  return '%d%di'%(self.realPart, self.imagPart)
          else:
              if self.imagPart &gt;=0:
                  return '%f+%fi'%(self.realPart, self.imagPart)
              elif self.imagPart &lt;0:
                  return '%f%fi'%(self.realPart, self.imagPart)
  
      def __div__(self, other):
          r1 = self.realPart
          i1 = self.imagPart
          r2 = other.realPart
          i2 = other.imagPart
          resultR = float(float(r1*r2+i1*i2)/float(r2*r2+i2*i2))
          resultI = float(float(r2*i1-r1*i2)/float(r2*r2+i2*i2))
          result = Complex(resultR, resultI)
          return result
  
  c1 = Complex(2,3)
  c2 = Complex(1,4)
  print c1/c2
  </code></pre>