标签:style http io color 使用 sp on div bs
__author__ = ‘Administrator‘# coding=utf-8class Test:name=‘Hero‘def age(self):return ‘I am 28 Old‘class Baidu():title=‘百度一下,你就知道‘def url(self):return ‘Http://www.baidu.com‘t=Test()print t.nameprint t.age()bai=Baidu()print bai.titleprint bai.url()#The Results:# Hero# I am 28 Old# 百度一下,你就知道# Http://www.baidu.com
_author__ = ‘Administrator‘# coding=utf-8class Test:name=‘Hero‘def age(self):return ‘I am 28 Old‘class Sohu:Sohu_title=‘搜狐一下,你就知道‘class Baidu(Test,Sohu):#继承Test、Sohu类,多重继承title=‘百度一下,你就知道‘def url(self):return ‘Http://www.baidu.com‘#调用Test、Sohu类属性new_name=Test.namesohu_news=Sohu.Sohu_title#函数中调用父类函数以及属性def new_num(self):return self.age()def sohu_title(self):return self.Sohu_titledef new_nn(self):return self.namebai=Baidu()print bai.new_name,‘\n‘,bai.new_num(),‘\n‘,bai.new_nn(),‘\n‘,bai.sohu_news#The Results:# Hero# I am 28 Old# Hero# 搜狐一下,你就知道
class Private:__name=‘Private funtion‘def name(self):return self.__namepp=Private()print pp.name()#外部调用私有属性print pp._Private__name#The Results#Private funtion
class Student(object):def __init__(self, name, score):self.name = nameself.score = scorestu=Student(‘Hero‘,‘python ‘)print stu.nameprint stu.score#The Results# Hero# python
__author__ = ‘Administrator‘# coding=utf-8import sysreload(sys)sys.setdefaultencoding("utf-8")#@classmethod 修饰符#通常情况下,如果我们要使用一个类的方法,那我们只能将一个类实体化成一个对象,进而调用对象使用方法。#正常不实用@classmetodclass Yest():def hero(self):return "Hello,Hero"a=Yest()print a.hero()#结果:Hello,Hero#使用#classmethod,classmethod修饰的函数第一个参数应该是cls,即调用类为第一个参数,而不能为空class Nest():@classmethoddef shero(cls):return "Hello,shero"@staticmethoddef hello():return "This is a staticmethod"print Nest.shero()print Nest.hello()#result:Hello,shero,This is a staticmethod#注意:@classmethod和@staticmetod区别在于,一个可以没参数一个必须要有cls参数
标签:style http io color 使用 sp on div bs
原文地址:http://www.cnblogs.com/hero-blog/p/4113519.html