Python global variable

前端 未结 6 1397
孤城傲影
孤城傲影 2020-12-16 14:49
def say_boo_twice():
  global boo
  boo = \'Boo!\'
  print boo, boo

boo = \'boo boo\'
say_boo_twice()

The output is

Boo! Bo

6条回答
  •  情深已故
    2020-12-16 15:37

    Essentially you reassign boo when you call the function.

    Check how this works with the globals() and locals() functions.

提交回复
热议问题