- 定义类有2种:新式类和经典类下面的Car为经典类如果Car(object)则为新式类
- 类名的命名规则按照‘大驼峰’
定义一个类,格式如下:
class 类名:
方法列表
demo:定义一个Car
# 定义类
class Car:
# 方法
def getCarInfo(self):
print('车轮子个数:%d, 颜色%s'%(self.wheelNum, self.color))
def move(self):
print("车正在移动...")
class 类名:
方法列表
demo:定义一个Car
# 定义类
class Car:
# 方法
def getCarInfo(self):
print('车轮子个数:%d, 颜色%s'%(self.wheelNum, self.color))
def move(self):
print("车正在移动...")