Home | Mirror | Search

第 30 章 Class

目錄

1.
class MyClass:
    """A simple example class"""
    i = 12345
    def f(self):
        return 'hello world'

x = MyClass()
    

1. 

def __init__(self):
    self.data = []
        
>>> class Complex:
...     def __init__(self, realpart, imagpart):
...         self.r = realpart
...         self.i = imagpart
...
>>> x = Complex(3.0, -4.5)
>>> x.r, x.i
        
comments powered by Disqus