因为在python中,列表、字典等如果只是修改其中元素的值,可以不用gloabl,如果是修改整个列表,必须是有gloabl。

 

为什么python在函数中修改"字典型全局变量"不需要global

nameList =['Python','Tab','.com']
def func3():
    nameList[0] = 'python'
func3()
print(nameList)

相关文章:

  • 2021-11-28
  • 2021-06-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2021-07-19
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案