首页 > 试题广场 >

What is the output of the last

[不定项选择题]
What is the output of the last "t()" in Python code?
    def t(a = []):
        a.append(1)
        print(a)

    t()
    t()
    t()
    t()

  • []
  • [1]
  • [1, 1, 1, 1]
  • [1,  [1, 1],  [1, 1, 1], [1, 1, 1, 1]]
每次调用时,a=[]。
发表于 2022-09-20 16:57:50 回复(0)
[1]
[1, 1]
[1, 1, 1]
[1, 1, 1, 1]
发表于 2022-06-06 10:57:02 回复(0)
是因为在全局运行,因此a是全局变量?
发表于 2020-09-07 14:58:55 回复(0)