美文网首页
python global variable

python global variable

作者: Ten_Minutes | 来源:发表于2019-02-23 11:22 被阅读0次

    if you want to simply access a global variable you just use its name. However to change its value you need to use the global keyword.

    change value:

    x = somevalue

    def func_A (): 

     global x

      # Do things to x 

     return x

    #just access x

    def func_B (): 

     print(x)

    相关文章

      网友评论

          本文标题:python global variable

          本文链接:https://www.haomeiwen.com/subject/wxnuyqtx.html