#!/usr/bin/python
# coding=utf-8
#class employee:
# 'all employee base'
# empcount = 0
# name = "default"
# salary = 20000
#
# def __init__(self,name,salary):
# self.name = name
# self.salary = salary
# employee.empcount += 1
#
# def displaycount(self):
# print "Total employee %d" % employee.empcount
#
# def displayemployee(self):
# print "Name:",self.name, ",Salary: ",self.salary
#
##use class
#emp1 = employee("Zara",2000)
#
#emp2 = employee("Jone",3000)
#
#
#'''
#emp1.displayemployee()
#emp2.displayemployee()
#
#print hasattr(employee,'name')
#print hasattr(employee,'salary')
#print hasattr(employee,'empcount')
#'''
#
#print "employee.__doc__:", employee.__doc__
#print "employee.__name__:", employee.__name__
#print "employee.__module__:", employee.__module__
#print "employee.__bases__:", employee.__bases__
#print "employee.__dict__:", employee.__dict__
#class Point:
# def __init__(self, x=0, y=0):
# self.x = x
# self.y = y
# def __del__(self):
# class_name = self.__class__.__name__
# print class_name,"destroy"
#
#pt1 = Point()
#pt2 = pt1
#pt3 = pt1
#print id(pt1),id(pt2),id(pt3)
#del pt1
#del pt2
#del pt3
class parent:#define parent
parentattr = 100
_protectedattr = 1
def __init__(self):
print "calling the parent class constructor"
def parentmethod(self):
print "calling parent class methods"
def setattr(self,attr):
parent.parentattr = attr
def getattr(self):
print "parent attributes", parent.parentattr
class child(parent):#define son
def __init__(self):
print "calling the son class constructor"
def childmethod(self):
print "calling the son method"
#c = child()
#c.childmethod()
#c.parentmethod()
#c.setattr(200)
#c.getattr()
#
#print issubclass(parent,child)
#print issubclass (child,parent)
#print isinstance(c,child)
c = parent()
print c._protectedattr
python类实例化及练习
最新推荐文章于 2024-02-15 10:13:18 发布