Hello World in Fortress

Our first program will print the classic “hello world” message. Here’s the full source code.

def main():
    print("hello world")

if __name__ == "__main__":
    main()

To run the program, save the code in a file named hello_world.py and use python to execute it.

$ python hello_world.py
hello world

Python does not need to be compiled before it is run. However, it is generally a good practice to make your scripts executable directly from the command line.

Make the script executable by adding a shebang line at the top:

#!/usr/bin/env python3

def main():
    print("hello world")

if __name__ == "__main__":
    main()

Then, change the file permissions to make it executable:

$ chmod +x hello_world.py
$ ./hello_world.py
hello world

Now that we can run and execute basic Python scripts, let’s learn more about the language.