Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do "In [X]:" and "Out[Y]:" mean in Python code?

Tags:

python

I'm a new Python user, and I'm sure this is a really basic question, but I can't find the answer anywhere. When people post Python code online it is often formatted like this:

In [1]: # some stuff
Out[1]:
# some more stuff

What are the In's, Out's, and the numbers? And why does my Python console not behave like that?

like image 259
Anthony Avatar asked May 08 '26 11:05

Anthony


1 Answers

They are not Python code. They are IPython prompts, a popular Python add-on interactive shell.

Each line of code executed on the interactive prompt (denoted by In) is numbered, and so is the output produced (denoted by Out). You can then instruct IPython to refer back to those inputs and outputs for re-running code or re-using output.

See the Input caching system documentation>

IPython offers numbered prompts (In/Out) with input and output caching (also referred to as ‘input history’). All input is saved and can be retrieved as variables (besides the usual arrow key recall), in addition to the %rep magic command that brings a history entry up for editing on the next command line.

like image 134
Martijn Pieters Avatar answered May 10 '26 12:05

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!