Data analysis foreplay: Ipython usage tips (UP)

Source: Internet
Author: User
Tags clear screen jupyter notebook

Do not necessarily have to use Jupyter Notebook, try Ipython command lineInstalling Ipython

I've only tried the Windows 10 environment.

1. After installing the Python installation package, you should have ipython.

2. Install anaconda, this do machine learning or data analysis if necessary, after this loading, there will be ipython. (Recommended use Anaconda, domestic mirror address:

Start Ipython

1. Command line input Ipython can be started.

2. Or find a shortcut, or you can start it.

Help?,python built-in Help method, I believe everyone will this. For example: Help (Len), and then it will show the documentation for the Len method:

2.? , Ipython Unique provides a shortcut character?, it can also access Help documentation, for example:

View Source??

Use?? To view Python's source code:

However, if the source code is not written in Python (some built-in methods are written in C and other languages), the following effects will appear:


The TAB key provides auto-complete or browse functionality when entered in Ipython.

Sometimes the advantages are like Python's built-in Dir () function, but much more powerful.

This is the effect of clicking tab on the back of L. The following is the effect of a smart hint after you enter a letter C:

Prompt for private properties

Use tab to display only the public and external properties/methods, if you want to display private properties, then by convention, you must first enter an underscore _.

You can also use the tab when import

Wildcard characters*

Sometimes the tab is not enough, so use the wildcard character *.

For example, display an object that ends with an error:

Notice there's another one behind?

* can match any string including an empty string.

Another example that contains the XXX string:

Shortcut keys

Navigation class:

CTRL + A, move the cursor to the beginning

Ctrl+e, move the cursor to the end of the line

Ctrl+b (or ←), move one character to the left

Ctrl+f (or →), move one character to the right

Input class:

Backspace: Delete the previous character in a row

Ctrl+d, delete the next character in a row

Ctrl+k, cut from the cursor position to the end of the line.

Ctrl+u, cut from the beginning of the line to the cursor position.

Ctrl+y, paste the text that you cut before.

Ctrl+t, swap the position of the first two characters.

Command History class:

Ctrl+p, the previous command, and ↑ as if.

CTRL + N, after a command, and ↓ looks the same.

Ctrl+r, reverse search.

Where ctrl+r is useful, for example:

When you press Ctrl+r, enter a, and the previous input will be searched in reverse order.

If you have the same historical search results, you can click on multiple ctrl+r to continue to flip forward.

Other shortcut keys:

Ctrl+l, clear screen

CTRL + C, interrupts the current Python command

Ctrl+d, Exit Ipython

Magic CommandCopy multiple lines of code %paste,%cpaste

Copying multiple lines of code using CTRL + C on the Ipython command line often causes problems (indentation, and so on), and uses the%paste command to solve this problem.

Enter%paste, and then enter, and the contents of your cut disk will be copied and executed in perfect.

%cpaste, similar to%paste, but it provides an interactive interface for entering multiple blocks of code.

Execute external code%run

Direct examples:

To perform timings for code:%timeit,%%timeit

Execution timing for a single line of code:%timeit:

To perform timings on multiple lines of code:%%timeit:

Help documentation for MAGIC commands:

With%MAIGC, you can view all the magic commands and their documentation.

With%lsmagic, you can list all the magical commands.

Input and output history

With Ipython shell, you must be particularly familiar with these in,out on the left.

However, they are not decorations, they are both variables .

In and out are two variables and are updated in real time as the command is entered.


In is a list, and out is a dictionary.

So you can view specific in and out like this:

It is important to note that not all in has output, for example [37].

Underline and previous output

Use an underscore _ to get the previous output, which is a variable, updated in real time.

Use two underscore __ to get the second-to-last output, with three underscores ___ to get the third-to-last output. (Command line without output is not included)

You can use up to three underscores and more than three to get the previous output using out[x] or _x : Where X is the command line number, not the number of forwards.

Suppress output

Sometimes after entering a command, we do not want it to output the result, that is, the last side of the line plus one ; Semicolon.

In this case, the 76th line will have no output, out[76] will not exist.

Related Magic commands:%history

Use%history to get the previous commands together:

Note that its parameter-n is followed by the interval of the command line number.

Data analysis foreplay: Ipython usage tips (UP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.