1

Was doing something this morning and thought this was weird. Why am I able to do this? I would think this should bounce back saying there is no rank attribute.

class EmployeeClass(object):
    __status = None

def __init__(self, status):
    self.__status = status

def get_status(self):
    return self.__status

def set_status(self, status):
    self.__status = status


John_Smith = EmployeeClass("Employed")
John_Smith.rank = 'Director'
print(John_Smith.rank)

This actually runs and returns "Director" to me. I don't quite understand that, this line should fail shouldn't it?

John_Smith.rank = 'Director'
jpp
  • 147,904
  • 31
  • 244
  • 302
WhitneyChia
  • 676
  • 2
  • 10
  • 24

0 Answers0