# 创建类名
class printTest():
def printColor(self,color):
print("打印颜色:%s" % (color))
def printNum(self,num):
print("打印数字:%d" % (num))
def printWeight(self,weight):
print("打印重量:%f" % (weight))
# 类的实例化
c = printTest()
c.printColor("白色")
c.printNum(6)
c.printWeight(50.7)
# 创建类名
class printTest():
color = "蓝色"
num = 9
weight = 86.7
def __init__(self,color,num,weight):
self.color = color
self.num = num
self.weight = weight
def printColor(self):
print("打印颜色:%s" % (self.color))
def printNum(self):
print("打印数字:%d" % (self.num))
def printWeight(self):
print("打印重量:%f" % (self.weight))
# 类的实例化
c = printTest("白色",6,34.5,)
c.printColor()
c.printNum()
c.printWeight()
print()
print(c.color)
print(c.num)
print(c.weight)
print()
print(printTest.color)
print(printTest.num)
print(printTest.weight)
print()
printTest.color = "黑色"
printTest.num = 3
printTest.weight = 20.1
print(printTest.color)
print(printTest.num)
print(printTest.weight)
print()
# 创建类名
# 父类
class printTestA:
def __init__(self):
self.num = printTestA
def printNumA(self):
print("打印数字A:%d" % (self.num))
class printTestB:
def __init__(self):
self.num = printTestB
def printNumB(self):
print("打印数字B:%d" % (self.num*10))
# 子类
class printTestAB(printTestA, printTestB):
pass
# 类的实例化
c = printTestAB()
c.num = 9
c.printNumA()
c.printNumB()
|