Search code examples
pythonoopcomputer-science

What are protected variales in Python?


I know about OOPS in Python, but I am still a bit confused with protected variables. Can anyone please tell me what they are


Solution

  • Variables are named locations of storage in the program. Based on access specification, variables can be public, protected and private in a class.

    Protected variables are those data members of a class that can be accessed within the class and the classes derived from that class. In Python, we follow conventions to indicate the access specification, like we use underscore ‘_’ symbol to determine the access control of a data member in a class. Any member prefixed with an underscore should be treated as a non-public part of the API or any Python code, whether it is a function, a method or a data member.