I'm learning Python, I've coded a bit in C++ before. I have simple very code:
class Car:
def __init__(self, mark):
self._mark = mark
class Bus:
def __init__(self):
self.audi = Car("Audi")
def display(self):
print(self.audi._mark)
def main():
bmw = Car("BMW")
print(bmw._mark)
reno = Bus()
reno.display()
main()
As far as I know in C++, only classes that inherit have access to "protected" attributes. So my questions:
- What is the purpose of using "protected" attributes / methods in Python?
- Why do I have access to the attribute
_mark
from the main function/classBus
?
Thank you for explain!