1.类的语法
定义类:
class 类名:
“””文档说明”””
def _init_(self,参数列表):
self.实例变量 = 参数
语法
class 类名
def __init__(self, 参数): #构造函数
self.数据 = 参数
"""
例子:
"""
创建手机类
数据:品牌,价格,颜色
行为:通话
"""
class Phone():
"""
"""
def __init__(self, brand, price, color):
self.brand = brand
self.price = price
self.color = color
def call(self):
print(self.brand, "通话")
#类名()是对象 变量来操作对象
p01 = Phone("小米",3000,"蓝色")#变量 = 类名(参数列表)
p01.call()#对象去.方法
p02 = Phone("苹果",8000,"白色")
p02.call()