title: Calculating Euclidean distance using Magic Methods in Python 3
body: <p>I have a code that calculates Euclidean distance for me:</p>
  
  <pre><code>class Point:
      """A point in two-dimensional space."""
  
      def __init__(self, x, y):
          self._x = x
          self._y = y
  
      def __eq__(self, other):
          return self._x == other._x and self._y == other._y
  
      def distance(self, other):
          new_x = self._x - other._x
          new_y = self._y - other._y
          print(new_x,'  ',new_y)
          return (new_x ** 2 + new_y ** 2) ** 0.5
  
  p1 = Point(10, 4)
  p2 = Point(3, 1)
  
  
  print('Euclidean distance : 'p1.distance(p2))
  </code></pre>
  
  <p>However, now I want to calculate this distance using magic methods in python like <code>__sub__</code> and <code>__pow__</code>. I've managed to implement <code>__sub__</code> but I don't know how to implement for <code>__pow__</code> and square root. This is my code so far:</p>
  
  <pre><code>class Point_1(object):
  
      def __init__(self, x, y):
          self._x = x
          self._y = y
  
  
      def setX(self, x,y):
          self._x = x
          self._y = y
  
      def getX(self):
          return self._x,self._y
  
  
      def __sub__ (self, other ):
          return Point_1(self._x - other._x, self._y - other._y)
  
      def __pow__(self,p):
          return Point_1(self._x ** p, self._y **p)
  
  
  
  
  p1 = Point_1(10,4)
  print(p1.getX())
  
  p2 = Point_1(3,1)
  print(p2.getX())
  
  p3 = p1 - p2
  </code></pre>
  
  <p>How can I implement the rest of the formula using magic methods. I'm really confused. Help would me appreciated.</p>