I am new to python and have recently started to study it full-time. I have been using vscode to type out my code I would run the script and it would show my output in the terminal window.
However, I cannot get a lot of the functions I create to display an output in the terminal window. However, as a comparison check, I ran the same code in a Jupyter notebook and it worked perfectly fine. I also tried running this code on another laptop in vscode running it as a python file. But nothing has worked.
Here is the code running as a python file in vscode:
Here is the code running in a jupyter notebook in vscode:
I apologise if I have been unclear. Do feel free to ask any questions to get a better understanding. I am a noob at this, so any help would be really encouraging. Thanks 🙂
2
Answers
Jupyter display in the console the value of the last line of code in a cell.
In normal Python scripts this does not happen. If you want to see the output in the console you need to use the
print()
function or similar.so in your case:
or
If you want to get a value from a function and use it elsewhere, you should return that value at the end of the function definition. That way when you call the function at some point in your code and you can assign it to a variable which would store the output of the function.
So you would need to use