定义一个类,格式如下:
class 类名:
属性列表
方法列表
demo:定义一个Car类
# 定义类
class Car:
# 属性
wheelNum = 2
color = 'red'
# 方法
def getCarInfo(self):
print('车轮子个数:%d, 颜色%s'%(self.wheelNum, self.color))
定义一个类,格式如下:
class 类名:
属性列表
方法列表
demo:定义一个Car类
# 定义类
class Car:
# 属性
wheelNum = 2
color = 'red'
# 方法
def getCarInfo(self):
print('车轮子个数:%d, 颜色%s'%(self.wheelNum, self.color))
转载于:https://www.cnblogs.com/loaderman/p/6561298.html