Home>Article>Backend Development> how to run python on linux
Linux has the Python program installed by default
Currently, most Linux distributions have two versions of the Python program installed
One is Python 2.x
The other is Python 3.x
Some system built-in program files require the support of Python 2, and Python 3 is the general trend
So , we’d better not touch the system’s Python version
Just declare which version you need to use directly
How to run Python:
We open the terminal on the Linux system
Enter python
The version and interpreter of Python 2 will pop up
Enter python3
The version of Python 3 will pop up Version and interpreter
So we generally enter the command to run the python 2 program
python program file
To run the python 3 program enter the command
python3 Program File
Here we use the default version of Python 3
Enter the command in the terminal
Python3
The pop-up Python interpreter starts with >>>
We can enter the Python program on it
It will directly output the result
For example:
We input 32 46 here, the output result is 78
Input print('hello python'), the output result is hello python
Note: When we run the .py file, the 32 46 will not be printed directly
You must add the print command
print(32 46)
We exit the python3 interpreter The shortcut key is not Ctrl C
but Ctrl Z
For more Python related technical articles, please visit thePython Tutorialcolumn to learn !
The above is the detailed content of how to run python on linux. For more information, please follow other related articles on the PHP Chinese website!