Taming Python: Hello World

Taming Pythons
Who’s strangling who?

In my first exercise to learn Python, I start with displaying a message.

✅ Step-by-step plan (pseudocode)

  1. Define a main function.
  2. Inside main, print "Hello World".
  3. Add the standard if __name__ == "__main__": entry point.
  4. Call main().

1, 2, and 4 are standard across most languages, aside from possibly a main function. Remembering my class on Haskell, specifically. That language is a completely different mindset.
Step 3 feels unusual. Why is it done this way? It turns out this is a side effect of Python being used for scripts/libraries for other programs as well as direct programs. For this simple example, it separates this program from being used as a library. While the consequences of a simple print line running out-of-place may be small, it seems a good practice, going forward.

✅ Finally, the complete Python code

It’s such a small program, but that is typical for this, and why this is often a 1st step in learning a new language.

Next step: modularization

By:


Leave a comment