<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    統計

    留言簿(1)

    DB

    Others

    QA

    Tech Website

    閱讀排行榜

    評論排行榜

    Special Methods for Customizing Classes

    Table 13.4. Special Methods for Customizing Classes

    Special Method

    Description

    Basic Customization

    C.__init__(self[, arg1, ...] )

    Constructor (with any optional arguments)

    C.__new__(self[, arg1, ...] )[a]

    Constructor (with any optional argu ments); usually used for setting up subclassing of immutable data types

    C.__del__(self)

    Destructor

    C.__str__(self)

    Printable string representation; str() built-in and print statement

    C.__repr__(self)

    Evaluatable string representation; repr() built-in and '' operator

    C.__unicode__(self)[b]

    Unicode string representation; unicode() built-in

    C.__call__(self, *args)

    Denote callable instances

    C.__nonzero__(self)

    Define False value for object; bool() built-in (as of 2.2)

    C.__len__(self)

    "Length" (appropriate for class); len() built-in

    Object (Value) Comparison[c]

    C.__cmp__(self, obj)

    object comparison; cmp() built-in

    C.__lt__(self, obj) and C.__le__(self, obj)

    less than/less than or equal to; < and <= operators

    C.__gt__(self, obj) and C.__ge__(self, obj)

    greater than/greater than or equal to; > and >= operators

    C.__eq__(self, obj) and C.__ne__(self, obj)

    equal/not equal to; ==,!= and <> operators

    Attributes

    C.__getattr__(self, attr)

    Get attribute; getattr() built-in; called only if attributes not found

    C.__setattr__(self, attr, val)

    Set attribute;

    C.__delattr__(self, attr)

    Delete attribute;

    C.__getattribute__(self, attr)[a]

    Get attribute; getattr() built-in; always called

    C.__get__(self, attr)[a]

    (descriptor) Get attribute

    C.__set__(self, attr, val)[a]

    (descriptor) Set attribute

    C.__delete__(self, attr)[a]

    (descriptor) Delete attribute

    Customizing Classes / Emulating Types

    Numeric Types: Binary Operators[d]

    C.__*add__(self, obj)

    Addition; + operator

    C.__*sub__(self, obj)

    Subtraction; - operator

    C.__*mul__(self, obj)

    Multiplication; * operator

    C.__*div__(self, obj)

    Division; / operator

    C.__*truediv__(self, obj)[e]

    True division; / operator

    C.__*floordiv__(self, obj)[e]

    Floor division; // operator

    C.__*mod__(self, obj)

    Modulo/remainder; % operator

    C.__*divmod__(self, obj)

    Division and modulo; divmod() built-in

    C.__*pow__(self, obj[, mod])

    Exponentiation; pow() built-in; ** operator

    C.__*lshift__(self, obj)

    Left shift; << operator

    Customizing Classes / Emulating Types

    Numeric Types: Binary Operators[f]

    C.__*rshift__(self, obj)

    Right shift; >> operator

    C.__*and__(self, obj)

    Bitwise AND; & operator

    C.__*or__(self, obj)

    Bitwise OR; | operator

    C.__*xor__(self, obj)

    Bitwise XOR; ^ operator

    Numeric Types: Unary Operators

    C.__neg__(self)

    Unary negation

    C.__pos__(self)

    Unary no-change

    C.__abs__(self)

    Absolute value; abs() built-in

    C.__invert__(self)

    Bit inversion; ~ operator

    Numeric Types: Numeric Conversion

    C.__complex__(self, com)

    Convert to complex; complex() built-in

    C.__int__(self)

    Convert to int; int() built-in

    C.__long__(self)

    Convert to long; long() built-in

    C.__float__(self)

    Convert to float; float() built-in

    Numeric Types: Base Representation (String)

    C.__oct__(self)

    Octal representation; oct() built-in

    C.__hex__(self)

    Hexadecimal representation; hex() built-in

    Numeric Types: numeric coercion

    C.__coerce__(self, num)

    Coerce to same numeric type; coerce() built-in

    C.__index__(self)[g]

    Coerce alternate numeric type to integer if/when necessary (e.g., for slice indexes, etc.)

    Sequence Types[e]

    C.__len__(self)

    Number of items in sequence

    C.__getitem__(self, ind)

    Get single sequence element

    C.__setitem__(self, ind, val)

    Set single sequence element

    C.__delitem__(self, ind)

    Delete single sequence element

    Special Method

    Description

    Sequence Types[e]

    C.__getslice__(self, ind1, ind2)

    Get sequence slice

    C.__setslice__(self, i1, i2, val)

    Set sequence slice

    C.__delslice__(self, ind1, ind2)

    Delete sequence slice

    C.__contains__(self, val)[f]

    Test sequence membership; in keyword

    C.__*add__(self, obj)

    Concatenation; + operator

    C.__*mul__(self, obj)

    Repetition; * operator

    C.__iter__(self)[e]

    Create iterator class; iter() built-in

    Mapping Types

    C.__len__(self)

    Number of items in mapping

    C.__hash__(self)

    Hash function value

    C.__getitem__(self, key)

    Get value with given key

    C.__setitem__(self, key, val)

    Set value with given key

    C.__delitem__(self, key)

    Delete value with given key

    C.__missing__(self, key)[g]

    Provides default value when dictionary does not have given key

    posted on 2011-07-21 23:25 XXXXXX 閱讀(251) 評論(0)  編輯  收藏 所屬分類: Python

    主站蜘蛛池模板: 中文字幕在线亚洲精品| 亚洲一线产品二线产品| 亚洲国产精品免费在线观看| 亚洲欧洲免费无码| 手机在线看永久av片免费| 亚洲国产精品人久久电影| 日本免费人成在线网站| 亚洲天堂一区二区三区四区| 国产成人精品免费视频网页大全 | 亚洲色图古典武侠| 美女被艹免费视频| 精品国产免费人成电影在线观看| 久久国产亚洲高清观看| 69xx免费观看视频| 亚洲日韩一区二区一无码| 日韩中文无码有码免费视频 | 亚洲国产精品嫩草影院久久| 亚洲国产超清无码专区| ww在线观视频免费观看| 亚洲欧洲精品成人久久曰| 亚洲国产成人爱av在线播放| 91免费国产视频| 亚洲高清资源在线观看| 日韩精品成人无码专区免费| AV激情亚洲男人的天堂国语| 美女被免费喷白浆视频| 久久亚洲中文字幕无码| 久久亚洲精品无码播放| 人妻无码久久一区二区三区免费| 国产亚洲精品看片在线观看| 暖暖在线视频免费视频| 亚洲不卡在线观看| 亚洲午夜无码片在线观看影院猛| 国产精品日本亚洲777| 中文字幕亚洲综合久久菠萝蜜| 亚洲精品免费视频| 亚洲人成在线电影| 精品久久免费视频| a国产成人免费视频| 亚洲av无码一区二区三区乱子伦| 国产四虎免费精品视频|