It's not that different from any other kind of if statement. The thing is, function definitions (not just declarations) are actually just like any other code, so you can do something like this (copy to a separate file and import as module):
X = 1
class A(object):
def __init__(self):
pass
def funcA(self):
return 'A'
if X == 0:
def funcB(self):
return 'B'
# then at console, if above is called 'modtest.py'...
import modtest
a = modtest.A()
a.<tab>
a.funcA
# Now change the above to say X = 0, and
reload(modtest)
a2 = modtest.A()
a2.<tab>
a2.funcA a2.funcB
The if X == 0
actually determines whether python will run the code that defines the function. Note that this is done at module import time - you can't change X 'on the fly' and get some A classes with funcB and some without; it only checks X once, when defining the class, and from then on just passes back the class A it already parsed.