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.

2.20. Useful Functions<br />

In this chapter, we have seen some useful built-in functions. We summarize them in Table 2.1 and<br />

present a few other useful ones (note that these may not be the full syntax, only what we feel would be<br />

useful for you now).<br />

Table 2.1. Useful Built-In Functions for New <strong>Python</strong> Programmers<br />

Function Description<br />

dir([obj]) Display attributes of object or the names of global variables if no<br />

parameter given<br />

help([obj]) Display object's documentation string in a pretty-printed format or<br />

enters interactive help if no parameter given<br />

int(obj) Convert object to an integer<br />

len(obj) Return length of object<br />

open(fn, mode) Open file fn with mode ('r' = read, 'w' = write)<br />

range([[start, ]stop[,step]) Return a list of integers that begin at start up to but not including stop<br />

in increments of step; start defaults to 0, and step defaults to 1<br />

raw_input(str) Wait for text input from the user, optional prompt string can be<br />

provided<br />

str(obj) Convert object to a string<br />

type(obj) Return type of object (a type object itself!)

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

Saved successfully!

Ooh no, something went wrong!