[Tutor] How to learn messages frim help()?

Alan Gauld alan.gauld at freenet.co.uk
Mon Jul 10 09:37:46 CEST 2006


> Hi,all.For example,I want learn build-in function TYPE,do help(type)
> and get message as following:
> 
> Help on class type in module __builtin__:
> 
> class type(object)
> |  type(object) -> the object's type
> |  type(name, bases, dict) -> a new type
> |
> |  Methods defined here:
> |
> |  __call__(...)
> |      x.__call__(...) <==> x(...)
> |
> |  __cmp__(...)
> |      x.__cmp__(y) <==> cmp(x,y)

> Have TYPE defined these methods?
> What relation with __call__,__cam__ etc?

I'm not sure what you are asking but yes, the help screen 
is telling you that the type class implements these 
methods and subtypes can overrride them.

Thus the type int is callable so we can do things like:

print int('45')

Similarly we can compare items of a given type 
because the cmp method is implemented, so 
we can do 

print type(5) == type(42)

Does that answer your question?

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list