#coding=utf-8class hello:def __init__(self,NAME):self.name=NAMEdef sayhello(self):print("Hello, {0}".format(self.name)) #拼接字符串,也可以用print("Hello "+self.name)#类的继承
class hi(hello): #父类用括号括起来def sayhi(self):print("Hi, {0}".format(self.name))h=hello("张三")
h.sayhello();h=hi("李四")
h.sayhi()
运行结果:
Hello, 张三
Hi, 李四