1 class Computer: # 创建类,类名首字母大写 2 screen = True # 类的属性 3 4 def start(self): # 创建实例方法,不要漏了 self 5 print('电脑正在开机中……') 6 # 类的实例化,实例名等于类名;调用的语法是实例名.属性和实例名.方法 7 my_computer = Computer() 8 print(my_computer.screen) 9 my_computer.start()
实例名.属性
实例名.方法