Please login


Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Difference between .py .pyc and pycache files

Difference between .py .pyc and pycache files

.py, .pyc. _pycache_ files

Python files are saved on the user machine with the file extension of “.py” as the C programing files are saved with .c extension and java files are saved with .java extensions. Python codes are then converted to bytecodes after they get interpreted. These bytecodes are saved in the file with the extension “.pyc”. The “_pycache_” files are the folder created to store the “.pyc” files. Let’s dig deeper on the Difference between .py .pyc and pycache files

Difference between .py and .pyc files.

Attribute .py file .pyc file
About These files store the source code of the Python programs These files store the bytecode of the Python programs
Speed Speed of the .py file is lower while generating output Speed of the .pyc file is higher than the .py file as it contains the compiled codes.
Code type .py files store the human-readable high-level python code .pyc files store the machine-readable low-level intermediate code
Data Content
Data in this file is interpreted by the interpreter of python
The data in this is the interpreted data which is ready to run on a virtual machine

.py files

.py extension used by the python to save the source code files. This is the script file format used by the python programing language. Python program can be written on any text editor but when we save the code with the extension “.py” the file is saved as the python file. These py files then can be executed on any machine where Python is installed. This file contains:

  • High-level
  • Human readable
  • Python source code

As the .py file enter the interpreter a duplicate file is created with the same name but the different extension and different data format. .py files are slower in execution because the python is an interpreted language.

.pyc files

.pyc extension is used to save the Interpreted bytecode. These type of files are created after the python source code are interpreted. Name of the file is the same as the name of the source code and are ready to run on a virtual machine. These files are faster in generating output as compared to .py files. “.pyc” files are:

  • Faster
  • Machine-readable
  • Low-level
  • Intermediate code

.pyc files are stored in a specific folder and are only created when the python source code is compiled. As these files are already interpreted speed of these files are faster than .py files.

_pycache_ files

All the interpreted files are stored in the _pycache_ files. We can say _pycache_ file is a folder containing all the interpreted .pyc files. The data in .pyc files in the _pycahce _ folder the is the bytecode representation of the python source code.