Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The problem in your first example is that when you do f(x), it is actually calling f and returning a value. However, you want to plot the function, not the return value from one call. So you should do this:

def f(x):
   if x>3:
   if x<=3:


Notice that now, I haven't called the function. Instead, I'm just passing the function into plot, and plot will call the function with different values.

Your lambda function trick works because it is passing a function into plot. plot then calls the lambda function, which in turn calls the f function. But I think it's easier to what I did above.