i = 1
def func():
    print( i + 1)
func() # 2

用global声明后,可以给i重新赋值。

i = 1
def func():
    global i
    i = i + 1
    print(i)
func() # 2

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-10-20
  • 2022-12-23
猜你喜欢
  • 2021-09-01
  • 2022-03-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案