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
| Piece | Role |
|---|---|
print(...) | Sends text to standard output (the terminal) |
| String | Text in quotes: "Hello" or 'Hello' |
| Script entry | Top-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.pyWith 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 namedHello. - Using smart/curly quotes from a word processor — use straight
"or'. - Expecting
printto return a value; it returnsNone. - On Windows, double-clicking a
.pymay flash a window and close; run from a terminal instead.