.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 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短