Pycharm returning value of defined variables


I'm making the jump from jupyter notebooks to pycharm. 

I'm noticing that when I run my script, the convention for showing the last few lines of code, even when variables are explicitly referenced, is very different between the two. 

For example, in Jupyter

Q1 = 2+2

Will result in returning the value for Q1, or 4. 

In pycharm when I run this code, I get no output in the run window. When I type:


I then get 4. 

Do I really have to wrap everything in print in order to get an output or am I missing something?

1 comment

It's not something PyCharm-specific. This is how Python works.
Jupyter Notebooks act similar to Python REPL (Read Eval Print Loop), which is why it automatically prints the result of the evaluation.

So, in short, yes, you have to use the print() function if you want to run your code as a script and see the output.
You can also run it in Python Console and you won't need the print() function in that case, but it may not be a good idea in the end if you need to run your code as a script somewhere on the server/CI.


Please sign in to leave a comment.