Python3: class vs instance vs private attributes

 Please be advised that this article is work-in-progress. The information here may be vague, incomplete, misleading or plainly wrong.  CLASS ATTRIBUTE VS INSTANCE ATTRIBUTE

An instance will try to search in its own namespace for an attribute -> If it can find it, it accesses it. -> If it can't find it, it will search the classes' namespace for it.

-> CLASS	-> exists in the CLASS' NAMESPACE ATTRIBUTE	-> attribute of the class -> once decalred, it is shared by all instances of the class -> the class will search for the attribute directly in its own namespace -> READ -> all instances of the class -> ob1 = class print(ob1.clsAttr) -> the class itself -> print(class.clsAttr) -> WRITE -> mutable attributes -> class -> YES -> instance -> YES -> it will write in the class' namespace directly, overriding the value for all clases -> immutable attributes -> class -> YES -> will override the value for all instances (existing or next) -> instances -> NO -> the instance will "copy" the attribute in its own namespace and assign the value -> USE CASE -> CONSTANTS -> a value that can be used by methods as a class-wide limit of sort -> an attribute that will store a piece of data for each instance -> like a class list that each instance will append to at instantiation

-> INSTANCE ATTRIBUTE -> exists only in the instance's namespace -> cannot be modified by the class -> cannot be modified by another instance -> the instance will search this attribute in its own namespace if it can't find it, it will search it in the class' namespace -> READ -> by the instance -> WRITE -> by the instance -> USE CASE -> for instance specific purposes

-> PRIVATE ATTRIBUTES -> a private variable has two underscores in front of its name -> will it still can be get or set, python tries to avid this by adding an underscore followed by the class' name in front of the variable -> ex: __attr from Class -> _Class__attr to access it

https://stackoverflow.com/questions/207000/what-is-the-difference-between-class-and-instance-attributes