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 559<br />

Table B-2. Opera<strong>to</strong>rs (Continued)<br />

Opera<strong>to</strong>r Description Precedence<br />

(...) Parenthesized expression or tuple display 21<br />

[...] List display 22<br />

{key:value, ...} Dictionary display 23<br />

`expressions...` String conversion 24<br />

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

Function<br />

abs(number)<br />

apply(function[, args[, kwds]])<br />

bool(object)<br />

callable(object)<br />

chr(number)<br />

cmp(x, y)<br />

complex(real[, imag])<br />

delattr(object, name)<br />

dict([mapping-or-sequence])<br />

dir([object])<br />

divmod(a, b)<br />

enumerate(iterable)<br />

eval(string[, globals[, locals]])<br />

execfile(file[, globals[, locals]])<br />

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

filter(function, sequence)<br />

Description<br />

Returns the absolute value of a number.<br />

Calls a given function, optionally with parameters.<br />

Returns True or False, depending on the Boolean<br />

value of object.<br />

Checks whether an object is callable.<br />

Returns a character whose ASCII code is the<br />

given number.<br />

Compares x and y—if xy, it returns a positive number; and if x==y, it<br />

returns zero.<br />

Returns a complex number with the given real<br />

(and, optionally, imaginary) component.<br />

Deletes the given attribute from the given object.<br />

Constructs a dictionary, optionally from another<br />

mapping or a list of (key, value) pairs. May also be<br />

called with keyword arguments.<br />

Lists (most of) the names in the currently visible<br />

scopes, or optionally (most of) the attributes of the<br />

given object.<br />

Returns (a//b, a%b) (with some special rules<br />

for floats).<br />

Iterates over (index, item) pairs, for all items<br />

in iterable.<br />

Evaluates a string containing an expression, optionally<br />

in a given global and local scope.<br />

Executes a <strong>Python</strong> file, optionally in a given global<br />

and local scope.<br />

Creates a file object with a given file name, optionally<br />

with a given mode and buffer size.<br />

Returns a list of the elements from the given<br />

sequence for which function returns true.

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

Saved successfully!

Ooh no, something went wrong!