What is the difference between py and pyc files in Python

0 votes

Hi, Team,

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

Jun 23, 2020 in Python by Roshni
• 10,420 points
1,579 views

1 answer to this question.

0 votes

Hi, @Roshni,

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.
answered Jun 23, 2020 by Gitika
• 65,870 points

Related Questions In Python

+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 58,100 points
1,022 views
+2 votes
2 answers

What is the difference between print and return in python?

Return statements end the execution of a ...READ MORE

answered Aug 25, 2019 in Python by anonymous
3,092 views
0 votes
0 answers

What is the difference between isdigit, isnumeric and isdecimal in python?

Can you give examples for each of ...READ MORE

May 31, 2019 in Python by Waseem
• 4,540 points
1,057 views
0 votes
1 answer

What is the difference between str() and repr() functions in Python?

str() is mostly used to create output ...READ MORE

answered Jul 8, 2019 in Python by Arvind
• 2,980 points
676 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,842 views
0 votes
0 answers
0 votes
5 answers
0 votes
1 answer

What is the difference between visual studio and idle in python programming??

Both are actually IDE-s I don't know ...READ MORE

answered Oct 16, 2020 in Python by Gitika
• 65,870 points
106 views