What is the difference between py and pyc files in Python

+1 vote

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,480 points
33,810 views

2 answers to this question.

+2 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,770 points
0 votes
.py File contain the source code a program

.pyc file contain the bytecode as a program
answered Nov 21, 2021 by anonymous

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,020 points
2,393 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 26, 2019 in Python by anonymous
8,034 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
2,254 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
• 3,050 points
1,613 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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
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,770 points
1,007 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP