0Pricing
Learn AI with Python · Lesson

Working with the Python REPL and IPython

Interactive exploration, tab completion, ?, %timeit, and shell commands in IPython.

Working with the Python REPL and IPython is a free Learn AI with Python lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Interactive Workflow

The REPL (Read-Eval-Print Loop) lets you experiment line by line. IPython is a supercharged REPL with introspection, magics, and history, and it powers Jupyter kernels.

pip install ipython
ipython

Docstrings with a Single ?

Append ? to any object to see its docstring and signature, no need to open documentation in a browser.

import numpy as np
np.arange?
# shows signature and docstring for arange

Source with Double ??

Use ?? to view the actual source code of a function (when written in Python). Great for understanding library internals.

def scale(x, factor=2):
    return x * factor

scale??
# prints the function source

Timing with %timeit

The same %timeit magic from notebooks works in IPython. It auto-tunes the number of loops for a stable measurement.

%timeit [i**2 for i in range(1000)]

Running Scripts with %run

%run script.py executes a file inside the current session, leaving its variables available afterward for inspection.

%run analysis.py
print(results)   # variable defined inside analysis.py

The Last Result: _

A single underscore _ holds the most recent output. Handy to reuse a result you forgot to assign.

In [1]: 10 * 5
Out[1]: 50

In [2]: _ + 1
Out[2]: 51

Older Results: __ and ___

Two underscores __ give the second-to-last result, three ___ the third-to-last. You can recover the last three outputs.

In [1]: 1
In [2]: 2
In [3]: 3
In [4]: ___, __, _
Out[4]: (1, 2, 3)

Output by Number

Every numbered output is stored. Out[3] (or _3) retrieves the result of cell 3 specifically.

In [3]: 7 * 6
Out[3]: 42

In [4]: Out[3] + 8
Out[4]: 50

Tab Completion

Press Tab after a dot to list an object's attributes and methods. This makes APIs discoverable without memorizing them.

import pandas as pd
pd.read_<TAB>
# read_csv  read_excel  read_json  read_parquet ...

Listing Variables with %who

%who lists names defined in the session; %whos adds type and value details for a richer overview.

x = 5
name = "ada"
%who
# name	x

%whos
# Variable  Type  Data/Info

Shell and History

IPython also runs shell commands with ! and recalls input history with %history, so you can copy earlier experiments.

!ls *.csv
%history -n 1-5   # show first five inputs with numbers

Quick Check

Test your IPython introspection skills.

Recap

IPython power tools:

  • obj? docstring, obj?? source
  • %timeit benchmarking, %run execute a file
  • _, __, ___ recall last three results; Out[n] any result
  • Tab completion for discovery
  • %who / %whos list variables

Frequently asked questions

Is the “Working with the Python REPL and IPython” lesson free?

Yes — the full text of “Working with the Python REPL and IPython” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.

What will I learn in “Working with the Python REPL and IPython”?

Interactive exploration, tab completion, ?, %timeit, and shell commands in IPython. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Learn AI with Python?

No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Working with the Python REPL and IPython” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Learn AI with Python lesson?

Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Virtual Environments and pip
  2. Jupyter Notebooks for Data Science
  3. Python Data Types for Data Science
  4. Working with the Python REPL and IPython
← Back to Learn AI with Python