In [ ]:
class Parent(object):
def __init__(self, name, age):
self.name = name
self.age = age
def mywork(self):
return "my work is artist"
class Child(Parent):
pass
In [ ]:
p = Parent('parent', 35)
c = Child('child', 18)
In [ ]:
print("Parent: %s" % p.name)
print("age: %i " % p.age)
print(p.mywork())
print("Parent: %s" % c.name)
print("age: %i " % c.age)
print(c.mywork())
In [ ]:
class Child(Parent):
def __init__(self, name, age, xxx):
self.unknow = xxx
def mywork(self):
return "%s's work is programer" % self.name
In [ ]:
c = Child('child', 18, 1234)
In [ ]:
c.name
In [ ]:
class Child(Parent):
def __init__(self, name, age, xxx):
Parent.__init__(self, name, age)
self.unknow = xxx
def mywork(self):
return "%s's work is programer" % self.name
In [ ]:
c = Child('child', 18, 1234)
print(c.name)
In [ ]:
super(Child, c)
In [ ]:
class Child(Parent):
def __init__(self, name, age, xxx):
super(Child, self).__init__(name, age)
self.unknow = xxx
def mywork(self):
return "%s's work is programer" % self.name
In [ ]:
c = Child('child', 18, 1234)
print(c.name)
In [ ]:
c.mywork()
In [ ]:
isinstance(c, Parent)
In [ ]:
isinstance(c, Child)
In [ ]:
isinstance(c, int)
In [ ]:
#isinstance(name, basestring)
In [ ]:
class Child(Parent):
def __init__(self, name, age, xxx):
super(Child, self).__init__(name, age)
self.unknow = xxx
def mywork(self):
return "%s's work is programer" % self.name
def doSomethingElse(self):
return "say hi"
In [ ]:
c = Child('chiled01', 20, 546465)
In [ ]:
c.doSomethingElse()
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.
# --------------------------------------------------------------------------------