Code execution order? | Sololearn: Learn to code for FREE!


Code execution order?

Is python code executed from top to bottom or is it executed by block from top to bottom? Im a little confused what exactly defines as a block too if someone could clarify

3/31/2017 8:54:44 PM

Hunter Gregan

4 Answers

New Answer


To be more precise, the code is *interpreted* top to bottom. So if you define a function or a class at the beginning of your program, it is interpreted but not executed until called. A block of code is a single semantic group of lines of code - a class definition, a for loop, an if statement - with all indented lines that come afterwards.


By default code executes from top to bottom (After every spacing, etc). But there are special cases where it doesnt for a few lines in a code.


top to bottom


Just adding is code contains a error (not syntax error) code is normal interpreted before the error line.