<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 閱讀(252) 評論(0)  編輯  收藏 所屬分類: Python

    主站蜘蛛池模板: 伊人免费在线观看| 麻豆高清免费国产一区| 国产h视频在线观看网站免费| 免费高清在线爱做视频| 亚洲啪啪AV无码片| 亚洲乱码日产精品一二三| 丝瓜app免费下载网址进入ios| 日韩免费一区二区三区在线| 亚洲国产成人久久综合碰| 亚洲国产av高清无码| 人妻免费久久久久久久了| 国产成人精品免费视| 国产成人精品久久亚洲| 亚洲人配人种jizz| 99精品免费视频| 日韩高清免费在线观看| 亚洲好看的理论片电影| 污污免费在线观看| 最近中文字幕mv手机免费高清| 亚洲人成人网站色www| 亚洲av无码一区二区三区天堂| 日本免费人成视频在线观看| 免费在线观看毛片| 亚洲中文字幕日本无线码| 中文字幕乱理片免费完整的| 国内一级一级毛片a免费| 亚洲第一区香蕉_国产a| 五月天国产成人AV免费观看| 久久精品女人天堂AV免费观看| 九月丁香婷婷亚洲综合色| 国产成人 亚洲欧洲| 91在线视频免费播放| 亚洲AV乱码久久精品蜜桃| 一区二区视频免费观看| 全免费a级毛片免费看不卡| 亚洲网站在线观看| 青青操视频在线免费观看| 亚洲av无码不卡私人影院| 亚洲另类无码一区二区三区| 91av在线免费视频| 亚洲高清国产拍精品26U|