import math class Complex: def __init__(self, real, imaginary): self.re = real self.im = imaginary def __str__(self): return "{}+i{}".format(self.re, self.im) def __repr__(self): return "[Complex: re = {}, im = {}, length = {}]".format( self.re, self.im, self.norm() ) def norm(self): return math.sqrt(self.re**2+self.im**2) def __eq__(self, other): return self.re == other.re and self.im == other.im def __ne__(self, other): return self.re != other.re or self.im != other.im def __lt__(self, other): return self.re < other.re and self.im < other.im def _my_secret_method(self, x): return Complex(x*self.re, x*self.im) class Example: exists = False number = 0 def __init__(self, x, y): self.radius = math.sqrt(x*x+y+y) self.x = x self.y = y Example.exists = True Example.number += 1 def __str__(self): return "Example: radius {}, x {}, y {}".format( self.radius, self.x, self.y)