-2

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

Puhalenthi
  • 11
  • 2
  • 3
    Does this answer your question? [Does Python have “private” variables in classes?](https://stackoverflow.com/questions/1641219/does-python-have-private-variables-in-classes) – r.ook Jul 17 '20 at 14:21

2 Answers2

0

With protected attributes ('_' in front of the attribute name) you explain politely to the person responsible for this, that the variable is protected and he should not access it or even worse, change it from outside the class.

However you are still able to access the variable from outside the class (unlike private ('__' before the attribute name) attributes.

Jens Becker
  • 1,471
  • 1
  • 7
  • 11
-1

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.

Aparna
  • 422
  • 2
  • 5