Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have protected class variables or methods in python? [duplicate]

Tags:

python

Is it possible to have protected class variables or methods in python? Can I see an example of such usage?

like image 550
surendrapanday Avatar asked Mar 30 '26 18:03

surendrapanday


1 Answers

The short answer is "no." There are conventions and good style that allow you to indicate that someone shouldn't be modifying those variables or calling those methods from outside the class but there is no way to strictly enforce this. There essentially is no such thing as strictly enforced private or protected variables or methods in Python.

See this tutorial.

like image 140
John Avatar answered Apr 02 '26 09:04

John