Section 2.20. Useful Functions


2.20. Useful Functions

In this chapter, we have seen some useful built-in functions. We summarize them in Table 2.1 and present a few other useful ones (note that these may not be the full syntax, only what we feel would be useful for you now).

Table 2.1. Useful Built-In Functions for New Python Programmers

Function

Description

dir([obj])

Display attributes of object or the names of global variables if no parameter given

help([obj])

Display object's documentation string in a pretty-printed format or enters interactive help if no parameter given

int(obj)

Convert object to an integer

len(obj)

Return length of object

open(fn, mode)

Open file fn with mode ('r' = read, 'w' = write)

range([[start, ]stop[,step])

Return a list of integers that begin at start up to but not including stop in increments of step; start defaults to 0, and step defaults to 1

raw_input(str)

Wait for text input from the user, optional prompt string can be provided

str(obj)

Convert object to a string

type(obj)

Return type of object (a type object itself!)




Core Python Programming
Core Python Programming (2nd Edition)
ISBN: 0132269937
EAN: 2147483647
Year: 2004
Pages: 334
Authors: Wesley J Chun

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net