Does Python basically execute code from the top to the bottom?

41 views Asked by At

I tried to inherit "Person" class to "Student" class:

class Student(Person):
  pass

class Person:
  pass

But I got this error:

NameError: name 'Person' is not defined

So, I changed the order of "Student" and "Person" classes:

class Person:
  pass

class Student(Person):
  pass

Finally, the error was solved.

Does Python basically execute code from the top to the bottom?

If yes, are there any special cases which Python executes code from the bottom to the top or which Python doesn't care about the order of code?

0

There are 0 answers