Skip to content

Instantly share code, notes, and snippets.

@TimurNurlygayanov
Created January 21, 2019 14:53
Show Gist options
  • Save TimurNurlygayanov/cf382ce6681805443c32ca1c030268af to your computer and use it in GitHub Desktop.
Save TimurNurlygayanov/cf382ce6681805443c32ca1c030268af to your computer and use it in GitHub Desktop.
parent_and_child_python2.py
class a(object):
__numbers = [1, 2, 3]
def input(self, numbers):
self.__numbers = numbers
def sum(self):
print(sum(self.__numbers))
class b(a):
def sum_x2(self):
print(2 * sum(self.__numbers)) # this will NOT work
def sum_x2_renamed(self):
print(2 * sum(self._a__numbers)) # this will work fine
my_object = b()
my_object.input([1, 5, 10])
my_object.sum_x2_renamed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment