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()

python中类的调用

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2021-08-11
  • 2022-12-23
  • 2022-01-12
猜你喜欢
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2023-03-17
  • 2022-12-23
相关资源
相似解决方案