0

This is a dumb question but I'm new to Python and couldn't figure out why my codes only works with Jupyter notebook and not in other IDEs or Text Editors. For example, I realized I always have to use the "Print" function to get my output in PyCharm and Sublime Text3 while I can just run values without the print function in Jupyter Notebook.

Here's a simple example: In Jupyter Notebook, I can simply run the codes without the print function

 x = 10
 y = 20
 x+y

if i run this, i still get my output, which is 30.

But if I do the same thing in PyCharm or Sublime Text3, I don't get the output. It just says [Finished in X.Xs] without printing my output and I always have to use the print function to get the output.

x=10
y=20
print(x+y)

I wonder what causes the difference. At first, I thought it was because of the type of software I was using and realized both Pycharm and Jupyter Notebook are IDEs. Do I need to change settings in order to make my codes work in Pycharm or Sublime Text3?

Thank you.

  • Can't comment Jupyter is built in a way such that you don't always need to use the print statement. I recommend you change the setting of jupyter as given [here](https://stackoverflow.com/questions/36786722/how-to-display-full-output-in-jupyter-not-only-last-result). – TheLegend42 Aug 31 '20 at 04:34

2 Answers2

0

Jupyter Settings is like that. It evaluates your last line of code, if it is 'None' prints nothing but if not None, would just get printed. Only the last uncommented expression or line gets printed nothing intermediate.

Sayan Dey
  • 771
  • 6
  • 13
0

Python essentially operates in two modes - script execution mode and interactive mode, otherwise known as REPL (Read, Evaluate, Print, Loop). Jupyter is set up by default to run in REPL mode, where the results of operations are printed to stdout (see this question to change this behavior).

In contrast, PyCharm and Sublime Text execute scripts straight through in non-interactive mode, and only print to stdout when explicitly directed to do so, such as with a call to print(). PyCharm has a REPL mode, as far as I know, and in Sublime you can use the SublimeREPL plugin, available from Package Control.

MattDMo
  • 100,794
  • 21
  • 241
  • 231