Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python类中同时运行两个函数_Python_Function_Class - Fatal编程技术网

在python类中同时运行两个函数

在python类中同时运行两个函数,python,function,class,Python,Function,Class,我发现有一种方法可以在类中同时运行这两个函数并呈现输出。 我想要的输出是['good','none second']而不调用Rodger.fun new=[] a=10 class Dog(): def fun(self): if a==10: new.append('good') else: new.append('none-first') return new def hi(se

我发现有一种方法可以在类中同时运行这两个函数并呈现输出。 我想要的输出是
['good','none second']
而不调用
Rodger.fun

new=[]
a=10
class Dog():
    def fun(self): 
        if a==10:
            new.append('good')
        else:
            new.append('none-first')
        return new
    def hi(self):
        if a==11:
            new.append('second-good')
        else:
            new.append('none-second')
        return new

Rodger = Dog()
Rodger.fun()
Rodger.hi()
输出:

['good', 'none-second']
['good', 'none-second']
初始化类时,可以调用
fun()
hi()

class Dog():
    def __init__(self, new):
        self.new = new
        self.fun()
        self.hi()
    def fun(self): 
        if a==10:
            self.new.append('good')
        else:
            self.new.append('none-first')
    def hi(self):
        if a==11:
            self.new.append('second-good')
        else:
            self.new.append('none-second')

new=[]
a=10
Rodger = Dog(new)
print(Rodger.new)
输出:

['good', 'none-second']
['good', 'none-second']

查看
multi-threading
threading
模块。因此,您希望不调用
fun
的返回值吗?创建一个调用
fun
hi
的函数怎么样?是的。正确@a_guest@Jai你为什么要这么做?