How can I check if code is executed in the IPython notebook?

I have some Python code example I'd like to share that should do something different if executed in the terminal Python / IPython or in the IPython notebook. How can I check from my Python code if...