[Tutor] how to get str() to use my function?

Alan Gauld alan.gauld at btinternet.com
Thu Aug 5 12:25:43 CEST 2010


"Alex Hall" <mehgcap at gmail.com> wrote

> It worked, thanks. Is there a list of these functions somewhere?


Learn to use the dir() and help() functions in Python at the >>> 
prompt.

dir(obj)

will show all the standard methods for that object.
For the math operators try dir(5) - or any other number, 5.0 for a 
float etc.
The advantage of dir() is a nice short listing, easy to scan.

For a detailed description use the help function:

>>> help(5)
Help on int object:

class int(object)
 |  int(x[, base]) -> integer
 |
 |  Convert a string or number to an integer, if possible.  A floating 
point
 |  argument will be truncated towards zero (this does not include a 
string
 |  representation of a floating point number!)  When converting a 
string, use
 |  the optional base.  It is an error to supply a base when 
converting a
 |  non-string. If the argument is outside the integer range a long 
object
 |  will be returned instead.
 |
 |  Methods defined here:
 |
 |  __abs__(...)
 |      x.__abs__() <==> abs(x)
 |
 |  __add__(...)
 |      x.__add__(y) <==> x+y
 |
 |  __and__(...)
 |      x.__and__(y) <==> x&y
 |
 |  __cmp__(...)
-- More  --

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list