+ 1

Why is there a main() function in Python? How do i use it?

Hi, my first language is Java (i'm in my first semester of computer science) and while learning Python i get confused as i see people using a main method and others that does not. If i teach this language, is it relevant to explain the main function? How do i correctly use it?

4th Jan 2020, 1:18 AM
Pame
Pame - avatar
1 ответ
+ 3
The main() function is basically used to run a program if the program is being run directly, not from another program. You basically create a main function, and call it like this: if __name__ == "__main__": #both have two underscores on both sides main()
4th Jan 2020, 1:24 AM
Jianmin Chen
Jianmin Chen - avatar