我如何访问类的实例变量作为自己方法的默认参数?

时间:2018-08-16 10:03:47

标签: python-3.x

我如何访问类的实例变量作为自己方法的默认参数? enter image description here

class DataAnalyst:

    data = [1] # i want to acess this instance##########################

    # def __init__(self,data):
    #      self.data = data


    def medien(self,data = self.data):put it as a defult parametert#############
        print("test",data)
        data.sort()
        index = len(data)

        # this mean values of our data is odd number
        if len(data) % 2 != 0:
            return data[int(((index + 1) / 2 - 1))]
        else:
            num1 = data[int(((index / 2) - 1))]
            num2 = data[int((index / 2))]
            return (num1 + num2) / 2

0 个答案:

没有答案