What is the differe...
Notifications
Clear all

What is the difference between py and pyc files

RSS

(@abhijith)
Noble Member
Joined: 1 year ago
Posts: 1350
27/04/2021 12:01pm

Can anyone tell me What is the difference between .py and .pyc files?


Quote
(@ganesh)
Noble Member
Joined: 1 year ago
Posts: 1362
27/04/2021 12:04 pm

You can follow a few steps given below:

  • .py files contain the source code of a program. Whereas, .pyc file contains the bytecode of your program. We get bytecode after compilation of .py file (source code). .pyc files are not created for all the files that you run. It is only created for the files that you import.
  • Before executing a python program python interpreter checks for the compiled files. If the file is present, the virtual machine executes it. If not found, it checks for .py file. If found, compiles it to .pyc file and then python virtual machine executes it.
  • Having .pyc file saves you the compilation time.

ReplyQuote
Share:
Baidu