0

I find this mildly irritating as I am unable to see the reason.

The return statement (within a function) in VS Code (+ bash terminal) doesn't return any value, unless I explicit say print(function()), like given in the code below.

This doesn't happen in Spyder, it promptly returns the value in the console.

Why is this so? What am I missing?

Python Code

Zephyr
  • 11,891
  • 53
  • 45
  • 80
Tuning
  • 53
  • 1
  • 5

2 Answers2

3

The main reason is that in Spyder you use IPython console. It is an interactive shell which provides extra features. Since in your bash terminal the Python console is used instead of IPython, it does not return the value of the function when it is prompted.

In this question, the differences between IPython and Python consoles are discussed.

Global
  • 46
  • 3
2

It is possible to use IPython in VS Code as well https://code.visualstudio.com/docs/python/jupyter-support-py

You may have to enable Python Data Science features in settings though (considered still experimental as of September 2020):

  • open the settings (press Ctrl+,) then search for datascience options

Personally, I find "Send Selection To Interactive Window" option very useful.

"python.dataScience.sendSelectionToInteractiveWindow": true,

Determines if selected code in a python file go to the terminal or to the Python interactive window when hitting Shift+Enter

algo99
  • 69
  • 3