将函数结果作为输入参数传递给类中的函数

时间:2016-04-12 10:27:05

标签: python

chrt_ventesArticles.Series[Conversion.Texto(f_cursor.Campo(1))]["PixelPointWidth"] = Conversion.Texto(Math.Round(chrt_ventesArticles.ChartAreas[0].InnerPlotPosition.Height, 0));

如何将 class main_prg: def func(): # code that generates x and y return x,y def func1(x): #uses the value of x that is returned from func() z=x+3 return z 传递给x

我试过了

func1()

给我一​​个错误m=main_prg() f01,f11 = m.func() f2 = m.func1(f01)

1 个答案:

答案 0 :(得分:0)

这可以为您提供所需的输出。您必须将self添加到类中的每个函数。

class main_prg:
      def func(self):
            # code that generates x and y
            x = 1 # whatever
            y = 2 # whatever
            return x,y
      def func1(self, x):
            #uses the value of x that is returned from func()
            z = 3 # whatever
            return z

m = main_prg()
f01,f11 = m.func()
print f01
print f11
f2 = m.func1(f01)
print f2
  • f01打印1
  • f11打印2
  • f2打印3