Python2:
To open a terminal, enter the following command:
[Email protected]:~$ vim helloa.py
In the Vim editor, enter edit mode (press i), enter the following code, and then exit edit mode (press ESC), save the file (press shift+ semicolon, and then press WQ to save the exit)
1 # !/usr/bin/python 2 3 Print " Hello Python2 " 4 Print 5/2
Then change the file executable permissions
[Email protected]:~$ chmod +x helloa.py
Then you can safely execute the helloa.py, just as you do other commands.
Python3:
With similar steps, we can enter a similar code like the following
1 # !/usr/bin/python3 2 3 Print ("hello python3") 4 Print (5/2)
The results of the implementation are as follows:
Summary, the first line in the Python code to #! The beginning, called Shebang, points to a script parser, which is consistent with writing shell scripts, and with this line we can use the script as a command.
Read Shebang, just a little bit of shell knowledge, never again do not have obsessive-compulsive disorder