0
from abc import ABC 


class Person(ABC):
    def __init__(self,name):
        self.__name = name

class Worker(Person):
    def __init__(self,name):
        super().__init__(name)
        print(self.__name)

Worker("Ania")

I want output "Ania", but I have this error instead:

'Worker' object has no attribute '_Worker__name'

Ser
  • 37
  • 6

1 Answers1

0

Change __name to _name or name, it'll work. In Python preceding dunders (double underscores) means Mangling. You can read more here.

XAMES3
  • 147
  • 1
  • 6