InterviewSolution
Saved Bookmarks
| 1. |
What is main function in python? How do you invoke it? |
|
Answer» In the world of programming languages, the MAIN is considered as an entry point of execution for a PROGRAM. But in python, it is known that the interpreter serially interprets the FILE line-by-line. This means that python does not provide main() function explicitly. But this doesn't MEAN that we cannot simulate the execution of main. This can be done by defining user-defined main() function and by using the __name__ property of python file. This __name__ variable is a special built-in variable that points to the name of the current module. This can be done as SHOWN below: def main(): print("Hi Interviewbit!")if __name__=="__main__": main() |
|