IPython Underscore Shortcuts and Suppressing Outputs

  • Underscore Shortcuts and Previous Outputs
    • Python shell standard shortcut: _ variable stores previous output.
    • IPython extends this:
    • __ stores the second-to-last output.
    • ___ stores the third-to-last output.
    • _X is a shorthand for Out[X], where X is the line number.
    • Example:
    • If Out[2] is 0.9092974268256817, then _2 will also return 0.9092974268256817.
  • Suppressing Output
    • To suppress output, add a semicolon ; at the end of the line.
    • The result is computed silently and not stored in the Out dictionary.
    • Example:
    • math.sin(2) + math.cos(2); computes the result without displaying or storing it.
    • 14 in Out will return False after executing the above command, indicating that line 14's output was not stored.