All valid Python syntax works as-is in IPython. Ipython also provides a number of extra features.
In the notebook, to run a cell of code, hit Shift-Enter
. This executes the cell and puts the cursor in the next cell below, or makes a new one if you are at the end. Alternately, you can use:
Alt-Enter
to force the creation of a new cell unconditionally.Control-Enter
executes the cell and keeps the cursor in the same cell.print("Hello world!")
Hello world!
import distutils
distutils.fancy_getopt?
distutils.fancy_getopt??
distutils.f*?
Pressing Shift-Tab
is another way of getting help
distutils.fancy_getopt()
distutils.f
this_is_a_variable = 42
this_is_a_function = lambda x: x
this_
!
in front of the commands¶!pwd
/Users/loris/projects/python_meetup/intro_ipython_notebook/notebooks
dir_list = !ls
print("The content of the directory is:\n\n{}".format(dir_list))
The content of the directory is: ['analysis.html', 'analysis_slideshow.slides.html', 'display.ipynb', 'enviroment.ipynb', 'example', 'example_file.txt', 'example_script.py', 'export.ipynb', 'figs', 'index.ipynb', 'installation.ipynb', 'magics.ipynb', 'output_toggle.tpl', 'parallel.ipynb', 'references.ipynb', 'use_of_ipython.ipynb']
!echo "The content of the directory is:\n"
!echo $dir_list
The content of the directory is: [analysis.html, analysis_slideshow.slides.html, display.ipynb, enviroment.ipynb, example, example_file.txt, example_script.py, export.ipynb, figs, index.ipynb, installation.ipynb, magics.ipynb, output_toggle.tpl, parallel.ipynb, references.ipynb, use_of_ipython.ipynb]
!echo {[item for item in dir_list if item.endswith(".ipynb")]}
[display.ipynb, enviroment.ipynb, export.ipynb, index.ipynb, installation.ipynb, magics.ipynb, parallel.ipynb, references.ipynb, use_of_ipython.ipynb]