cs107-lecture-examples

Example codes used during Harvard CS107 lectures
git clone https://git.0xfab.ch/cs107-lecture-examples.git
Log | Files | Refs | README | LICENSE

05.py (298B)


      1 #!/usr/bin/env python3
      2 class Complex():
      3     """Complex number type"""
      4     def __init__(self, real, imag):
      5         self.real = real  # real part
      6         self.imag = imag  # imaginary part
      7 
      8 
      9 z = Complex(1, 2)
     10 print(z.__dict__)
     11 print(vars(z))
     12 print(Complex)
     13 print(type(z))
     14 print(z.real)
     15 print(z.imag)