16.01.2014 Views

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

APPENDIX B ■ PYTHON REFERENCE 561<br />

Table B-3. Some Important Built-in Functions (Continued)<br />

Function<br />

min(object1, [object2, ...])<br />

oct(number)<br />

open(filename[, mode[, bufsize]])<br />

ord(char)<br />

If object1 is a nonempty sequence, the smallest<br />

element is returned; otherwise, the smallest of<br />

the supplied arguments (object1, object2, . . .) is<br />

returned.<br />

Converts an integer number <strong>to</strong> an octal string.<br />

An alias for file (use open, not file, when<br />

opening files).<br />

Returns the ASCII value of a single character (a string<br />

or Unicode string of length 1).<br />

pow(x, y[, z]) Returns x <strong>to</strong> the power of y, optionally modulo z.<br />

range([start, ]s<strong>to</strong>p[, step])<br />

raw_input([prompt])<br />

reduce(function, sequence[,<br />

initializer])<br />

reload(module)<br />

repr(object)<br />

reversed(sequence)<br />

round(float[, n])<br />

setattr(object, name, value)<br />

sorted(iterable[, cmp][, key][,<br />

reverse])<br />

str(object)<br />

sum(seq[, start])<br />

tuple([sequence])<br />

type(object)<br />

unichr(number)<br />

unicode(object[, encoding[, errors]])<br />

Description<br />

Returns a numeric range (as a list) with the given<br />

start (inclusive, default 0), s<strong>to</strong>p (exclusive), and step<br />

(default 1).<br />

Returns data input by the user as a string, optionally<br />

using a given prompt.<br />

Applies the given function cumulatively <strong>to</strong> the items<br />

of the sequence, using the cumulative result as the<br />

first argument and the items as the second argument,<br />

optionally with a start value (initializer).<br />

Reloads an already loaded module and returns it.<br />

Returns a string representation of the object, often<br />

usable as an argument <strong>to</strong> eval.<br />

Returns a reverse itera<strong>to</strong>r over the sequence.<br />

Rounds off the given float <strong>to</strong> n digits after the decimal<br />

point (default zero).<br />

Sets the named attribute of the given object <strong>to</strong> the<br />

given value.<br />

Returns a new sorted list from the items in iterable.<br />

Optional parameters are the same as for the list<br />

method sort.<br />

Returns a nicely formatted string representation of<br />

the given object.<br />

Returns the sum of a sequence of numbers, added <strong>to</strong><br />

the optional parameter start (default 0).<br />

Constructs a tuple, optionally with the same items as<br />

the supplied sequence.<br />

Returns the type of the given object.<br />

The Unicode version of chr.<br />

Returns a Unicode encoding of the given object,<br />

possibly with a given encoding, and a given mode<br />

for handling errors (either 'strict', 'replace', or<br />

'ignore', 'strict' being the default).

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

Saved successfully!

Ooh no, something went wrong!