.py和.pyc文件有什么区别?
Python编译.py文件并将其另存为.pyc文件
.pyc包含Python源文件的编译字节码,不会为您执行的主程序文件创建.pyc(仅对于导入的模块)。
.pyc文件包含编码的python字节码。
如果要导入模块,则模块将计算两个数的加法
示例
def recursive_sum(n):
"""Function to return the sum of recursive numbers"""
if n <= 1:
return n
else:
return n + recursive_sum(n-1)
# change this value for a different result
number = 16
if number < 0:
print("Enter a positive number")
else:
print("The sum is",recursive_sum(number))输出结果
The sum is 136
如果您以“example”的名称存储该程序,那么当您运行example.py文件时,该程序将被存储为“example.py”,一旦代码首次执行,将需要一些时间来创建example.pyc文件。.py文件,其中代码首先由编译器以“example.pyc”文件的形式转换为字节码。
热门推荐
10 舞蹈老师晚安祝福语简短
11 亲戚红包生日祝福语简短
12 给老公祝福语简短2026
13 家庭英语祝福语短句简短
14 男友人新婚祝福语简短
15 金店立秋祝福语简短英文
16 虎年新年专属祝福语简短
17 新进单位敬酒祝福语简短
18 单位搬迁新楼祝福语简短