15.04.2013 Views

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

Core Python Programming (2nd Edition)

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Numeric Types: base representation<br />

(string)<br />

C.__oct__(self) Octal representation; oct() built-in<br />

C.__hex__(self) Hexadecimal representation; hex() built-in<br />

Numeric Types: numeric coercion<br />

C.__coerce__(self, num) Coerce to same numeric type; coerce() built-in<br />

Sequence Types [d]<br />

C.__len__(self) Number of items in sequence<br />

C.__getitem__(self, ind) Get single sequence element<br />

C.__setitem__(self, ind, val) Set single sequence element<br />

C.__delitem__(self, ind) Delete single sequence element<br />

C.__getslice__(self, ind1, ind2) Get sequence slice<br />

C.__setslice__(self, i1, i2, val) Get sequence slice<br />

C.__delslice__(self, ind1, ind2) Delete sequence slice<br />

[f] Test sequence membership; in keyword<br />

C.__contains__(self, val)<br />

C.__*add__(self, obj) Concatenation; + operator<br />

Sequence Types [d]<br />

C.__*mul__(self, obj) Repetition; * operator<br />

[e] Create iterator class; iter() built-in<br />

C.__iter__(self)<br />

Mapping Types<br />

C.__len__(self) Number of items in mapping<br />

C.__hash__(self) Hash function value<br />

C.__getitem__(self, key) Get value with given key<br />

C.__setitem__(self, key, val) Set value with given key<br />

C.__delitem__(self, key) Delete value with given key<br />

[a] New in <strong>Python</strong> 2.2; for use with new-style classes only.<br />

[b] New in <strong>Python</strong> 2.3.<br />

[c] All except cmp() new in <strong>Python</strong> 2.1.<br />

[d] "* " either nothing (self OP obj), "r " (obj OP self), or "i " for in-place operation (new in <strong>Python</strong> 2.0), i.e., __add__,

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!