19 a = '我是模块中的变量a'
20 
21 def hi():
22     a = '我是函数里的变量a'
23     print('函数“hi”已经运行!')
24 
25 class Go2:
26     a = '我是类2中的变量a'
27     def do2(self):
28         print('函数“do2”已经运行!')
29 
30 print(a)  # 打印变量“a”
31 
32 hi()  # 调用函数“hi”
33 
34 A = Go2()  # 实例化“Go2”类
35 print(A.a)  # 打印实例属性“a”
36 A.do2()  # 调用实例方法“do2”

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2021-11-14
  • 2021-07-04
  • 2021-12-18
猜你喜欢
  • 2021-11-29
  • 2022-02-01
  • 2022-12-23
  • 2021-11-24
  • 2021-07-07
  • 2022-12-23
相关资源
相似解决方案