Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python's Equivalent of "public static void main"

Tags:

java

python

What is Python's equivalent of "public static void main(String[] args) { ... }"? I remember having used it in the past and then forgot.

What I'm basically trying to remember is a function which I think included some underscores (__)...

thx

like image 496
Devoted Avatar asked May 25 '10 19:05

Devoted


People also ask

What is static void in Python?

In contrast, public static void main(String args[]) is a special method signature that tells the Java VM what what method of what class to start with. Python just starts at the top of the named module and begins running from there.

What is public static void Main called?

The keyword public static void main is the means by which you create a main method within the Java application. It's the core method of the program and calls all others. It can't return values and accepts parameters for complex command-line processing.

What if I write static public void main instead of public static void main?

It will work. Nothing will happen ! It was nothing the program compiles and runs properly.

Why main method is public static void main in Java?

When java runtime starts, there is no object of the class present. That's why the main method has to be static so that JVM can load the class into memory and call the main method. If the main method won't be static, JVM would not be able to call it because there is no object of the class is present.


1 Answers

#!/usr/bin/env python

import sys

def main(args):
    print args

if __name__ == '__main__':
    main(sys.argv)

edit: emulate a void return.

like image 156
Santa Avatar answered Sep 18 '22 14:09

Santa