#class的定义
class example:
def __init__(self, name):
example.name = name
#或者
class example(object):
def __init__(self, name):
example.name = name
class son(father):
def __init__(self, name):
example.name = name
class example:
def __init__(self, name):
example.__name = name
#__name就是私有
python的继承是多态的,但是却不是严格多态的
class father(object):
def run(self):
print("father")
class son(father):
pass
class other(object):
def run(self):
print("other")
def run2(father):
father.run()
father.run()
run2(father())
run2(son())
run2(other())
#皆可
type("abc") == str
isinstance("abc", str)
#一次性获得所有属性和方法
dir(father())
#或者
dir(father)
获得,设置,是否存在某个属性attr
hasattr(father, "run")
setattr(father, "__document__", "test")
getattr(father, "__document__")