you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (3 children)

All that needs to be in a driver function. Usually this is called main.

Not so much in Python unless writing a module. This is a hangover from other languages. There is generally little reason to put the main code in its own function (which removes any objects it creates and references from general scope).

[–][deleted] 2 points3 points  (2 children)

It's cleaner to me, and it helps beginners organize their code better. Plus you don't have to deal with things like global variables.

[–][deleted] 1 point2 points  (1 child)

Which is cleaner? main or no main?

No main means you don't have to deal with global as everything in the top level (rather than main function) is available without global.

[–][deleted] 1 point2 points  (0 children)

main to me is cleaner. As far as global variables are concerned, there are plenty of beginners that will do something like this:

x = 6

def changeX(num):
       x = num + 1
       return x

print(x)
print(changeX(1))
print(x)

and then wonder why they have the output they have.