Class
![](https://i-blog.csdnimg.cn/direct/7171f5a85f32421385e35a7f68e9f780.png)
class MyClass:
"""A simple example class"""
i = 12345
def f(self):
return 'hello world'
x = MyClass()
1.7.1. __init__ 构造方法
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
1.7.2. inner class(内嵌类)
#!/usr/bin/env python3
import os, sys
class parent:
def __init__(self):
self.name = 'parent'
def getName(self):
print(self.name)
class child:
def __init__(self):
self.name = 'child'
def getName(self):
print(sel