Yesterday I ran Python on Windows, and today I learned Python on Linux.
Generally, Python has been installed on Linux. As long as we enter the command # python on the terminal, the interaction interface of Python is displayed, and The >>> prompt is displayed.
The Python version of my Linux system is 2.7. Although Python 3 and Python 2 are somewhat different, I should first learn the version of Python 2, and finally learn the difference with Python 3.
How to exit the Python interactive mode on Linux: >>> exit ()
I started writing the Python program!
Python program Extension:. py
Enter # vim 1.py in the Linux Command Line, enter the vim editor, and enter print "Hello world". Save and exit. We have written this Python program.
In this way, enter # python1.py in the command line and use the Python interpreter to explain the 1. py script.
Helloworld will appear on the screen.
In addition, we can use./1.py to execute it. Before that, we must add the Python path to the first line of 1. py:
#! /Usr/bin/python
And: add the executable permission to 1. py: chmod + x 1.py, so that we can execute it in./1. py.
Python file type:
Source code:
-The Python source code file uses the "py" extension, which is explained by the python program and does not need to be compiled;
Byte Code:
-Python source files with the extension "pyc" generated after compilation;
Compilation Method:
We need to write a Python program to compile 1.py.
Vim 2.py
Import py_compile
Py_compile.compile ("1. py ")
Input # python2.py on the Linux Command Line to generate a 1. pyc file (binary file)
# Python 1.pyc so that you can execute it.
Optimization code:
-Optimized source file with the extension ". pyo"
-Python-O-m py_compile 1.py
Generate a 1.pyo File
# Python 1.pyo execution