Using a variable outside of function in Python

后端 未结 4 1163
误落风尘
误落风尘 2021-01-03 08:18

A really simple question, and I\'m sure I knew it but must have forgotten

When running this code:

x = 0
def run_5():
    print \"5 minutes later\"
           


        
4条回答
  •  一向
    一向 (楼主)
    2021-01-03 08:56

    Just return a value ?

    x = 0
    def run_5():
        print "5 minutes later"
        x += 5
        return x
    
    x=run_5()
    print x
    

提交回复
热议问题