0

In C, I'd do something like

int main() {
    return 42;
}

and after executing the program, I can(in Linux) prompt echo $? to the console to get the desired 42 as the return signal from the last operation. How can I do that in python?

I tried just creating a file with a return 42 in it, but it says that it is not inside a function(obviously).

Garmekain
  • 664
  • 5
  • 18
  • [sys.exit()](https://docs.python.org/2/library/sys.html#sys.exit), or the newer [atexit](https://docs.python.org/2/library/atexit.html#module-atexit) – Robert Harvey Jul 05 '18 at 20:13

1 Answers1

2

exit(42)

will give you the desired behaviour.

Hongyu Wang
  • 378
  • 1
  • 10