Cannot call a variable from another function

后端 未结 4 773
陌清茗
陌清茗 2021-01-24 08:07

I edited my thread based on feedback. Basically, I need to use a couple of variables from function 1, and I need to print it in function 2.

How do I go about doing that?

4条回答
  •  长发绾君心
    2021-01-24 08:39

    just use the return statement it'll work like charm

    def function_one():
        num=5
        return num
    
    def function_two():
        print(function_one())
    
    function_two()
    

提交回复
热议问题