|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Python OOP
How come Python never implemented a ``stronger'' (is that the right word?) OOP system (ie. more like C++/Java) with private/public stuff?
|
|
#2
|
||||
|
||||
|
Python does have private and public methods (no protected though). If you prefix a method name with __, then it is only visible within that class.
Code:
class class1:
def method1(self):
print "Hello from Method 1"
def __method2(self):
print "Method 2"
def method3(self):
self.__method2()
In the above code, method1() and method3() are public and can be accessed from other modules, but __method2() can only be accessed from within this class.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month Looking for a perl job with kick-*** programmers in a well-known NASDAQ listed tech company with branches in the US and Europe? We're hiring. PM me for details. Requirements |
|
#3
|
|||
|
|||
|
Woah, I never new that
. Is it the same for variables? |
|
#4
|
|||
|
|||
|
Quote:
Because it's not useful to artificially restrict the visibility to things within classes. Especially not in a language like Python. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Python OOP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|