[Solved]How python executes. What is the difference between the two programmes? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

[Solved]How python executes. What is the difference between the two programmes?

1. print("hello") print (a) 2. print ("hello") print (a) Both are same but I have given space in 2nd line of first program. Outputs: 1. error comes 2. Hello error comes Why it is showing only error for the first one but prints hello and then error for the second one?

8th May 2020, 6:04 AM
Puthur Harthik
6 Answers
+ 3
You can read this to get more background on how a python program is executed. https://realpython.com/invalid-syntax-python/ First stage is that the program is parsed and converted to python bytecode. At this time python does a syntax check, and indentation errors (among others) will cause a failure and stop the program from executing at all. If the syntax is correct then the execution will proceed line by line, and from that point, only runtime errors might interrupt the program.
8th May 2020, 7:28 AM
Tibor Santa
Tibor Santa - avatar
+ 9
Thanks Tibor Santa now i understood clearly. Thanks Oma Falk for your help.
8th May 2020, 7:34 AM
Puthur Harthik
+ 7
Thanks for answering Oma Falk . But in c program won't run if atleast one error exist. But here in second case it is opposite. Can u explain that please.
8th May 2020, 6:38 AM
Puthur Harthik
+ 7
Python is interpreter language. So executes line by line. Then in 1st program it should print hello and then it should show error when it comes to second line. I understood like this. Can u correct it please.
8th May 2020, 7:04 AM
Puthur Harthik
+ 4
Hi, In python indents belong to syntax. Th indents are the curly brackets in c....more or less
8th May 2020, 6:35 AM
Oma Falk
Oma Falk - avatar
+ 2
Python is an interpreter language.no compiling.
8th May 2020, 6:59 AM
Oma Falk
Oma Falk - avatar