Переглянути джерело

add `__neg__` for complex

blueloveTH 2 роки тому
батько
коміт
9d9ec9a6d0
1 змінених файлів з 3 додано та 0 видалено
  1. 3 0
      python/cmath.py

+ 3 - 0
python/cmath.py

@@ -69,6 +69,9 @@ class complex:
     
     def __abs__(self) -> float:
         return math.sqrt(self.real ** 2 + self.imag ** 2)
+
+    def __neg__(self):
+        return complex(-self.real, -self.imag)
     
     def __hash__(self):
         return hash((self.real, self.imag))