{article Dive into Python}{title} {text} {/article}

The callable function takes any object and returns True if the object can be called, or False otherwise. Callable objects include functions, class methods, even classes themselves.

The below I could not get it to work in Python 3.4.0, but it would work in Python 2.7.6

import string


string.punctuation


string.join

callable(string.punctuation)


print string.join.__doc__

The functions in the string module are deprecated (although many people still use the join function), but the module contains a lot of useful constants like this string.punctuation, which contains all the standard punctuation characters.

string.join is a function that joins a list of strings.

string.punctuation is not callable; it is a string. (A string does have callable methods, but the string itself is not callable.)

string.join is callable; it's a function that takes two arguments.

Any callable object may have a doc string. By using the callable function on each of an object's attributes, you can determine which attributes you care about (methods, functions, classes)and which you want to ignore (constants and so on) without knowing anything about the object ahead of time.

Work in Python 2.7.6

This did not work in Python 3.4.1

I don't know if this is the same but it worked in Python 3.4.1

import string
string.punctuation
str.join
callable(string.punctuation)
print (str.join.__doc__)