Code Reference

Hello World

Python · Reference cheat sheet

Hello World

Python · Reference cheat sheet


📋 Overview

A “Hello World” program is the smallest useful program: it prints a message so you know the language toolchain works. In Python that is usually one print call.

🔧 Core concepts

PieceRole
print(...)Sends text to standard output (the terminal)
StringText in quotes: "Hello" or 'Hello'
Script entryTop-level code runs when you execute the file
__name__Equals "__main__" when the file is run directly

You can run code in the REPL or save it in a .py file. Files are better for anything you want to keep.

💡 Examples

One-liner in the REPL:

print("Hello, World!")

Minimal script (hello.py):

print("Hello, World!")
python hello.py

With a main guard (good habit):

def main():
    print("Hello, World!")


if __name__ == "__main__":
    main()

Slightly richer greeting:

name = "Ada"
print(f"Hello, {name}!")
print("Welcome to Python.")

⚠️ Pitfalls

  • Forgetting quotes: print(Hello) looks for a variable named Hello.
  • Using smart/curly quotes from a word processor — use straight " or '.
  • Expecting print to return a value; it returns None.
  • On Windows, double-clicking a .py may flash a window and close; run from a terminal instead.

On this page