Hello World in Python πΒΆ
Prerequisites: Python Installation
Mentor's Note: Every great developer started with this one line of code. Welcome to the world of programming! π‘
π The Scenario: The First Meeting π€ΒΆ
Imagine you are meeting a new friend for the first time.
- The Logic: You want to say "Hello" so they know you're there. π¦
- The Result: A friendly greeting! In programming, we tell the computer to say "Hello" to us to prove everything is working. β
π» Your First ScriptΒΆ
Create a file named hello.py and write exactly this:
# π Scenario: Greeting the world
# π Action: Using the built-in print function
print("Hello, World!")
# ποΈ Outcome: The text appears on your screen
How to Run it?ΒΆ
- Open your terminal or command prompt.
- Navigate to the folder where you saved
hello.py. - Type:
python hello.py
π Understanding the CodeΒΆ
print(): This is a built-in Function. Think of it as a worker whose only job is to put things on the screen."Hello, World!": This is a String (text). Strings MUST be inside quotes ("or').- Parentheses
(): These tell the function what data to work with.
π§ Step-by-Step LogicΒΆ
- Start π
- Call the
printworker. - Hand the worker the message "Hello, World!".
- The worker displays the message.
- End π
π Sample Dry RunΒΆ
| Step | Action | Description |
|---|---|---|
| 1 | print() called |
Python finds the printing tool π₯ |
| 2 | Argument received | Message "Hello, World!" is loaded π¦ |
| 3 | Execution | Text is pushed to the terminal π€ |
π― Practice Lab π§ͺΒΆ
Task: Personalized Greet
Task: Modify your script to print your own name instead of "World". Bonus: Try printing two different messages on two different lines.
π Common Mistakes β οΈΒΆ
- Missing Quotes:
print(Hello)will cause an error because Python thinksHellois a variable. - Wrong Case:
Print("Hi")will fail becauseprintmust be lowercase.
π‘ Pro Tip: "The best way to predict the future is to invent it." - Alan Kay
β Back: Installation | Next: Module 2 - Syntax & Comments β