Public - Private - Protected

An excellent example demonstrating the difference between the various access modifiers can be found here and summarized below:

http://greenethumb.com/article/27/public-private-protected-internal-access-modifiers-in-as3/


public access modifier allows every Class access

// hey everyone, beer is on me!!!

public function bar():Beer { ... }

internal access modifier allows Classes sharing this package access

//my good package-mates, have some beer on me!

internal function bar():Beer { ... }

protected access modifier allows subclasses access

// I will only give beer to my children ( they are 21, i swear! )

protected function bar():Beer { ... }

private access modifier allows no external access

// My beer is just that, MINE!

private function bar():Beer { ... }


In Python, you use the underscore to define private methods. But they aren't really private, they're just mangled to hide them. A single underscore makes a variable or method private. A double underscore prevents a subclass from overwriting it and a double underscore before and after is reserved for Python iteslef.


Here is a better explanation:

http://igorsobreira.com/2010/09/16/difference-between-one-underline-and-two-underlines-in-python.html