<ol>
<li><code>.py</code>:这通常是您编写的输入源代码。</li>
<li><code>.pyc</code>:这是编译的字节码。如果您导入一个模块,python将构建一个包含字节码的<code>*.pyc</code>文件,以便以后更容易(更快)地再次导入它。</li>
<li><code>.pyo</code>:这是一个<code>*.pyc</code>文件,在优化(<code>-O</code>)打开时创建。</li>
<li><code>.pyd</code>:这基本上是一个windows dll文件。<a href="http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll" rel="noreferrer">http://docs.python.org/faq/windows.html#is-a-pyd-file-the-same-as-a-dll</a></li>
</ol>
<p>关于<code>.pyc</code>与<code>.pyo</code>的进一步讨论,请看:<a href="http://www.network-theory.co.uk/docs/pytut/CompiledPythonfiles.html" rel="noreferrer">http://www.network-theory.co.uk/docs/pytut/CompiledPythonfiles.html</a>(我复制了下面的重要部分)</p>
<blockquote>
<ul>
<li>When the Python interpreter is invoked with the -O flag, optimized code is generated and stored in ‘.pyo’ files. The optimizer currently doesn't help much; it only removes assert statements. When -O is used, all bytecode is optimized; .pyc files are ignored and .py files are compiled to optimized bytecode.</li>
<li>Passing two -O flags to the Python interpreter (-OO) will cause the bytecode compiler to perform optimizations that could in some rare cases result in malfunctioning programs. Currently only <code>__doc__</code> strings are removed from the bytecode, resulting in more compact ‘.pyo’ files. Since some programs may rely on having these available, you should only use this option if you know what you're doing.</li>
<li>A program doesn't run any faster when it is read from a ‘.pyc’ or ‘.pyo’ file than when it is read from a ‘.py’ file; the only thing that's faster about ‘.pyc’ or ‘.pyo’ files is the speed with which they are loaded.</li>
<li>When a script is run by giving its name on the command line, the bytecode for the script is never written to a ‘.pyc’ or ‘.pyo’ file. Thus, the startup time of a script may be reduced by moving most of its code to a module and having a small bootstrap script that imports that module. It is also possible to name a ‘.pyc’ or ‘.pyo’ file directly on the command line.</li>
</ul>
</blockquote>
<p><strong>注意:</strong></p>
<p>2015年9月15日,<a href="https://docs.python.org/3/whatsnew/3.5.html#pep-488-elimination-of-pyo-files" rel="noreferrer">Python 3.5 release</a>实施了PEP-488并删除了<code>.pyo</code>文件。
这意味着<code>.pyc</code>文件同时表示未优化和优化的字节码。</p>