In [ ]:
class Man(object):
def __init__(self, name, money):
self.name = name
self.money = money
# privite
self.__priviteMoney = 100
def getMoney(self):
return self.money
def __getPrivteMoney(self):
return self.__priviteMoney
In [ ]:
man = Man('A', 1000)
In [ ]:
man.__priviteMoney
In [ ]:
man.__getPrivteMoney()
In [ ]:
class Man(object):
def __init__(self, name, money):
self.name = name
self.money = money
# privite
self.__priviteMoney = 100
def getMoney(self):
return self.money + self.__priviteMoney
def __getPrivteMoney(self):
return self.__priviteMoney
In [ ]:
man = Man('B', 2000)
In [ ]:
man.getMoney()
In [ ]:
class Man(object):
def __init__(self, name, money):
self.name = name
self.money = money
# privite
self.__priviteMoney = 100
def getMoney(self):
return self.money + self.__getPrivteMoney()
def __getPrivteMoney(self):
return self.__priviteMoney
def setPriviteMoney(self, money):
self.__priviteMoney = money
In [ ]:
man = Man('C', 3000)
In [ ]:
man.getMoney()
In [ ]:
man.setPriviteMoney(500)
In [ ]:
man.getMoney()
In [ ]:
class Man2(Man): pass
In [ ]:
man2 = Man2('D', 50000)
In [ ]:
man2.getMoney()
In [ ]:
man2.setPriviteMoney(1000)
In [ ]:
man2.getMoney()
In [ ]:
man._Man__priviteMoney
In [ ]:
class Man(object):
def __init__(self, name, money):
self.name = name
self.money = money
# privite
self._myMoney = 300
self.__priviteMoney = 100
def getMoney(self):
return self.money + self.__getPrivteMoney()
def _getMyMoney(self):
return self._myMoney
def __getPrivteMoney(self):
return self.__priviteMoney
def setPriviteMoney(self, money):
self.__priviteMoney = money
In [ ]:
man = Man('A', 30000)
In [ ]:
man._myMoney
In [ ]:
man._myMoney = 400
In [ ]:
man._getMyMoney()
In [ ]:
# --------------------------------------------------------------------------------
# Copyright (c) 2013 - 2014 Mack Stone. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# --------------------------------------------------------------------------------