What is In[]: and Out[]:?

Asked

Viewed 242 times

1

For some time I am writing some basic scripts with Python, in some tutorials sometimes I come across In []: and Out[], Usually equal values appear to the forehead. Below is a small example.

In [24]: a = float("Nan")

In [25]: b = a

In [26]: b is a
Out[26]: True

In [27]: b == a
Out[27]: False

In [28]: a == a
Out[28]: False

2 answers

7

The In[]: is how some interactive environments put the prompt for you to type a Python expression. It is in place of the >>>, that you see when you call "Python" or "Idle".

Already the Out[] is just a prefix to the return value of an expression. They are used in Jupyter Notebook, but also in "ipython" which can be used in the shell (cmd in windows), in place of normal Python.

In practice, if it’s an example of interactive elements, you just type in everything that comes after the In[]: after the >>> of your Python.

Also I recommend using the ipython, without the notebook itself, in place of the standard interactive environment (The Python executable that runs from the inside is the same - you only get a few more features - in particular, you can interactively edit blocks of code, which the default environment forces you to edit line by line). Just type pip install ipython and call "ipython" instead of "python3".

  • Another advantage of ipython compared to normal shell is that the presence/absence of the Out[] makes it clear when a value is returned and when it is printed, which tends to confuse enough for those who are starting.

2


Probably the tutorials you are seeing are being programmed and run in environments like the Jupyter Notebook. JN is a virtual environment for code education as it makes it easier visually to teach code structures, at least compared to a conventional output of an IDE.

It is quite common in Youtube tutorials, especially those from the United States, according to my experience.

Thus, the In and 'Out's that you see is nothing more than a code input line (In) and the exit line (Out). If you run in a conventional IDE, like Pycharm, you’ll see that there’s no difference in code, syntax, and input/output values.

Of course has the JN can have a much deeper application, but usually I see it being used for this purpose platform for easier display of code. More hints here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.