Класс Python, атрибутPython

Программы на Python
Anonymous
Класс Python, атрибут

Сообщение Anonymous »

У меня возникли проблемы со следующим кодом:

Код: Выделить всё

class Esempio():
def __init__(self, a, b, c):
self.a = a
self._b = b
self.__c = c

def __str__(self):
return f"a={self.a} b={self._b} c={self.__c}"

def geta(self):
return self.a

def getb(self):
return self._b

def getc(self):
return self.__c

print('costruisco istanza di esempio')
ex1 = Esempio("uno", "due", "tre")

ex1.__c = 'querty' # __C is private
ex1.__d = 'abc'    # __d is not defined in the class
ex1.e = 'defghj'   # e is not defined in the class
почему последние три инструкции НЕ вызывают исключение?

Подробнее здесь: https://stackoverflow.com/questions/798 ... -attribute

Вернуться в «Python»