Hello World in Python ๐¶
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 โ