Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (47.6k points)

I've been given to understand that Python is an interpreted language... However, when I look at my Python source code I see .pyc files, which Windows identifies as "Compiled Python Files". Where do these come in?

1 Answer

0 votes
by (106k points)
edited by

The .pyc files that you are seeing contain byte code, the byte code is the set of codes that results after the compilation of source code by the Python interpreter. This code is then executed by Python's virtual machine.

The definition which tells how Python is Interpreted in Python's documentation is as follows: 

Python is an interpreted language, as opposed to a compiled one, though the distinction can be blurry because of the presence of the bytecode compiler. This means that the source files can be run directly without explicitly creating an executable which is then run/executed.

In particular, the .pyc files you are seeing are cached bytecode files produced by CPython.

The CPython compiles the source files into a Python-specific lower-level form (known as "bytecode"), does so automatically when needed (when there is no bytecode file corresponding to a source file, or the bytecode file is older than the source or compiled by a different Python version), usually saves the bytecode files to disk (to avoid recompiling them in the future). 

To know more about this you can have a look at the following video tutorial:-

Related questions

+2 votes
1 answer
0 votes
1 answer
0 votes
0 answers
asked Dec 29, 2020 in Python by sadha (120 points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...