Python is an interpreted language. The Python interpreter can only run one command at a time. The standard Python interpreter environment can be entered by typing python (after typing python in the terminal, you can enter the interpreter):
>>>
It is a prompt, telling you that you can enter commands. If you want to exit, you can type exit()
or press Ctrl-D.
Running the python program is also very simple, just enter a terminal python+.py file. Suppose our hello_world.py file has the following content
print('Hello world')
You can run it with the following command (remember, hello_world.py must be in the current folder):
If you are doing scientific calculations and data analysis, we usually use IPython, which is an enhanced version of the python interpreter, and Jupyter notebook is a web-based code notebook, which is also developed from the IPython project. Here is a brief introduction to IPython and Jupyter and how to use it. For more information, see Appendix B. When we use the %run
command, IPython will execute the file in the way of executing code, allowing us to visually see the result of the interaction:
The default IPython prompt will display numbers, such as the In [2]:
in the picture, instead of the normal >>>
prompt.
Recommended Posts