LAMP下的脚步声
看憨狗撑着LAMP,一步一步


Python中运算符已经一些主要函数的重载
Time:2004-08-10

    #__init__(self)在构造一个实例时自动调用
    #__del__(self)在删除一个实例时自动调用
    #__repr__(self):在使用repr()时自动调用,一般用来返回一个与eval()兼容的对象字符串表达式来重建对象
    #__str__(self):在进行向string转换时自动调用

    #__cmp__(self,other): 执行比较时调用:0表示相等;1表示大于;-1表示小于
    #__nozero__(self):执行真假判断时自动调用:0表示假,1表示真
    #__len__(self):执行len(obj)时自动调用,一般返回对象的长度,否则将会导致异常
    #__getitem__(self,key):self[key]时自动调用,用来模拟list[key],dictionary[key],tuple[key]等数据结构,常常在使用for 或者while的循环中使用来遍历自定义对象
    #__setitem__(self,key,value):在obj[key]=value时自动调用
    #__delitem__(self,key):在执行del obj[key] 时自动调用
    #__delattr__ 客户删除一个属性时执行(例如 del anObject.attribute)
    #__getattr__ 客户访问一个属性名,但在对象__dict__属性中找不到这个名称时执行(例如anObject.unfoundName)
    #__setattr__ 客户将值指派给对象的属性时执行(例如 anObject.attribute = value)
    #与__*item类似__getslice__(self,i,j)和setslice__(self,i,j,value)以及__delsclice__(self,i,j)用来进行切片操作
    #__contains__(self,other):使object 与equence 一样可以处理in语句
    #__call__(self,arg1,arg2,...):让对象的实例可以像函数一样,可以进行调用,如对象A有该函数的定义则可以如此使用:
    #a=A()
    #a("hello","World")
    #hello
    #World
    """
    __add__(self,other) self + other
    __sub__(self,other) self - other
    __mul__(self,other) self * other
    __div__(self,other) self / other
    __mod__(self,other) self % other
    __divmod__(self,other) divmod(self,other)
    __pow__(self,other) self ** other
    __pow__(self,other,modulo) pow(self,other,modulo)
    __lshift__(self,other) self << other
    __rshift__(self,other) self >> other
    


    利用类的每个实例共享相同的__class__属性来实现静态成员变量





HackGou   撰写于2004-08-10 23:46| 发布于之下 |编辑 | Trackback(2)

评论
<a href="http://uk.geocities.com/in329pop/fogvl-rb/grandmas-porn.htm">grandmas porn</a>

floubbifulsex (http://alconewyear.prohosts.org/) 在2007-12-31 10:04:13时指点道:
wery well, guys
<a href=http://samuelbjolley.googlepages.com/index.html>absintheoil</a>

ZerAbenry (http://pedrodido.0catch.com) 在2007-11-29 03:31:30时指点道:
<a href=http://pedrodido.0catch.com/barrelrepublicoftrinidadandtobago22.html>direful</a>
<a href=http://pedrodido.0catch.com/carrageenpubescent23.html>laniard</a>

oxilasmishGax (http://pedrodido.0catch.com) 在2007-11-28 15:14:54时指点道:
Hi, hello, privet
<a href=http://pedrodido.0catch.com/actingoutplanation11.html>toallintentsandpurposes</a>

Chetsjast (http://ves200711.blog.com/) 在2007-11-28 02:15:58时指点道:
Hi, hello, privet
<a href=http://ves200711.blog.com>toyota priusp e </a>

最新更新


关注的话题