How is a protected member in Python different from a private member?

  • Private can be accessed outside the class with a warning.
  • Protected can be accessed only within the class.
  • Protected can be accessed outside the class with a warning.
  • They are the same.
In Python, a protected member is different from a private member in that it can be accessed outside the class, but it's considered a convention not to do so. It can be accessed with a warning, unlike private members, which are intended to be accessed only within the class itself.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *