0

how can i access instance variable of class as defult paramter for own method? 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
Rafał
  • 685
  • 6
  • 13
  • Please fix your code, `self` has no sense outside of a class – gogaz Aug 16 '18 at 10:07
  • Possible duplicate of [Can I use a class attribute as a default value for an instance method?](https://stackoverflow.com/questions/4041624/can-i-use-a-class-attribute-as-a-default-value-for-an-instance-method) – Rafał Aug 16 '18 at 10:09

0 Answers0