code: def is_ipynb():
      
      try:
          shell = get_ipython().__class__.__name__
          if shell == 'ZMQInteractiveShell':  # Jupyter notebook or qtconsole?
              return True
          elif shell == 'TerminalInteractiveShell':  # Terminal running IPython?
              return False
          else:
              return False  # Other type (?)
      except NameError:
          return False
docs: Return True if the module is running in IPython kernel,
      False if in IPython shell or other Python shell.
  
      Copied from: http://stackoverflow.com/a/37661854/1592810
      There are other methods there too
  
      >>> is_ipynb()
      False