IPython - Getting Started

This chapter will explain how to get started with working on IPython.

Starting IPython from Command Prompt.

Before proceeding to understand about IPython in depth, note that instead of the regular >>>, you will notice two major Python prompts as explained below −

  • In[1] appears before any input expression.

  • Out[1] appears before the Output appears.

Besides, the numbers in the square brackets are incremented automatically. Observe the following screenshot for a better understanding −

IPython Command Prompt

Now, if you have installed Anaconda distribution of Python, open Anaconda prompt from start menu.

Anaconda prompt

Start IPython from conda prompt

When compared to regular Python console, we can notice a difference. The IPython shell shows syntax highlighting by using different colour scheme for different elements like expression, function, variable etc.

IPython shell

Another useful enhancement is tab completion. We know that each object has one or more methods available as defined in its class. IPython pops up appropriate list of methods as you press tab key after dot in front of object.

In the following example, a string is defined. As a response, the methods of string class are shown.

String Class Methods

IPython provides information of any object by putting ‘?’ in front of it. It includes docstring, function definitions and constructor details of class. For example to explore the string object var defined above, in the input prompt enter var?. The result will show all information about it. Observe the screenshot given below for a better understanding −

IPython Info

Magic Functions

IPython’s in-built magic functions are extremely powerful. There are two types of magic functions.

  • Line magics, which work very much like DOS commands.
  • Cell magics, which work on multiple lines of code.

We shall learn about line magic functions and cell magic functions in detail in subsequent chapters.