繁体   English   中英

如何在另一个python中使用函数的变量

[英]how to use function's variable in another one python

我想在另一个函数中使用 [a] 的函数变量,是否可以使用全局变量或类? 如果是的话如何

 def apple():
     a = 2
 def orange():
     if a == 2:
         print('your fruit is apple')

我不是懒惰,我花了时间找到答案,但我找不到,所以了解我的低技能编程。

把它放到一个类中,如:

class fruit:
    a = 0
    def apple(self):
            self.a = 2
    def orange(self):
            if(self.a == 2):
                print('your fruit is apple')
a = fruit()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM