Main() Function

What I think the main() function does is that it is basically the part of the code which ‘runs’. Everything that is to be run needs to be present inside that main() function for it to be executed. This is my theory. Since I’ve only coded in Python & Javascript before, this seems quite unfamiliar!

1 Like

This is exactly it. In JavaScript it’s a bit like using the $(document).ready(...) in jquery to initialise your scripts and in python, it would be creating a single function called main then call that.

Most older (pascal and fotran for example) and C-based languages (Java, C++,C and C#) actually use a common entry function or method to start with. In fact, it’s actually more specifically compiled languages.

Python is a scripting language so it executes whatever is not inside a function first, top to bottom and only when functions are called do they execute. This would be more like windows batch files or powershell scripts.

1 Like

Privacy & Terms