Show More
@@ -1,11 +1,11 b'' | |||||
1 | ================================== |
|
1 | ======== | |
2 | Using IPython for interactive work |
|
2 | Tutorial | |
3 | ================================== |
|
3 | ======== | |
4 |
|
4 | |||
5 | This section of IPython documentation will walk you through most of the IPython |
|
5 | This section of IPython documentation will walk you through most of the IPython | |
6 | functionality. You do not need to have any deep knowledge of Python to read this |
|
6 | functionality. You do not need to have any deep knowledge of Python to read this | |
7 | tutorial, though some sections might make slightly more sense if you have already |
|
7 | tutorial, though some sections might make slightly more sense if you have already | |
8 | done some work in the REPL. |
|
8 | done some work in the classic Python REPL. | |
9 |
|
9 | |||
10 | .. note:: |
|
10 | .. note:: | |
11 |
|
11 |
@@ -10,12 +10,56 b' more than the standard prompt. Some key features are described here. For more' | |||||
10 | information, check the :ref:`tips page <tips>`, or look at examples in the |
|
10 | information, check the :ref:`tips page <tips>`, or look at examples in the | |
11 | `IPython cookbook <https://github.com/ipython/ipython/wiki/Cookbook%3A-Index>`_. |
|
11 | `IPython cookbook <https://github.com/ipython/ipython/wiki/Cookbook%3A-Index>`_. | |
12 |
|
12 | |||
|
13 | If you haven't done that yet see `how to install ipython <install>`_ . | |||
|
14 | ||||
13 | If you've never used Python before, you might want to look at `the official |
|
15 | If you've never used Python before, you might want to look at `the official | |
14 | tutorial <http://docs.python.org/tutorial/>`_ or an alternative, `Dive into |
|
16 | tutorial <http://docs.python.org/tutorial/>`_ or an alternative, `Dive into | |
15 | Python <http://diveintopython.net/toc/index.html>`_. |
|
17 | Python <http://diveintopython.net/toc/index.html>`_. | |
16 |
|
18 | |||
17 | The four most helpful commands |
|
19 | Start IPython by issuing the ``ipython`` command from your shell, you should be | |
18 | =============================== |
|
20 | greeted by the following:: | |
|
21 | ||||
|
22 | Python 3.6.0 | |||
|
23 | Type 'copyright', 'credits' or 'license' for more information | |||
|
24 | IPython 6.0.0.dev -- An enhanced Interactive Python. Type '?' for help. | |||
|
25 | ||||
|
26 | In [1]: | |||
|
27 | ||||
|
28 | ||||
|
29 | Unlike the Python REPL, you will see that the input prompt is ``In [N]:`` | |||
|
30 | instead of ``>>>``. The number ``N`` in the prompt will be used later in this | |||
|
31 | tutorial but should usually not impact the computation. | |||
|
32 | ||||
|
33 | You should be able to type single line expressions and press enter to evaluate | |||
|
34 | them. If an expression is incomplete, IPython will automatically detect this and | |||
|
35 | add a new line when you press ``Enter`` instead of evaluating. | |||
|
36 | ||||
|
37 | Feel free to explore multi-line text edition. Unlike many other REPL with | |||
|
38 | IPython you can use the up and down arrow keys when editing multi-line | |||
|
39 | code blocks. | |||
|
40 | ||||
|
41 | Here is an example of a longer interaction with the IPython REPL we often refer | |||
|
42 | to as an IPython _session_ :: | |||
|
43 | ||||
|
44 | In [1]: print('Hello IPython') | |||
|
45 | Hello IPython | |||
|
46 | ||||
|
47 | In [2]: 21 * 2 | |||
|
48 | Out[2]: 42 | |||
|
49 | ||||
|
50 | In [3]: def say_hello(name): | |||
|
51 | ...: print('Hello {name}'.format(name=name)) | |||
|
52 | ...: | |||
|
53 | ||||
|
54 | We won't get into details right now, but unlike the standard python REPL you | |||
|
55 | will notice a few difference. First your code should be syntax-highlighted as | |||
|
56 | you type. | |||
|
57 | ||||
|
58 | Second, you will see that some results will have an ``Out[N]:`` prompt, while | |||
|
59 | some other do not. We'll come to this later. | |||
|
60 | ||||
|
61 | The four most helpful commands | |||
|
62 | ============================== | |||
19 |
|
63 | |||
20 | The four most helpful commands, as well as their brief description, is shown |
|
64 | The four most helpful commands, as well as their brief description, is shown | |
21 | to you in a banner, every time you start IPython: |
|
65 | to you in a banner, every time you start IPython: | |
@@ -70,8 +114,8 b' in line and cell mode::' | |||||
70 | 100000 loops, best of 3: 7.76 us per loop |
|
114 | 100000 loops, best of 3: 7.76 us per loop | |
71 |
|
115 | |||
72 | In [2]: %%timeit x = range(10000) |
|
116 | In [2]: %%timeit x = range(10000) | |
73 |
|
|
117 | ...: max(x) | |
74 |
|
|
118 | ...: | |
75 | 1000 loops, best of 3: 223 us per loop |
|
119 | 1000 loops, best of 3: 223 us per loop | |
76 |
|
|
120 | ||
77 | The builtin magics include: |
|
121 | The builtin magics include: |
General Comments 0
You need to be logged in to leave comments.
Login now