Python Hello World Tutorial
Python Hello World: Your First Program
Welcome to your first Python tutorial! In this guide, you’ll learn how to create and run a simple “Hello World” program in Python.
What You’ll Learn
- How to install Python
- Creating your first Python file
- Running Python code
- Basic syntax and structure
- Next steps for learning
Step 1: Install Python
First, make sure you have Python installed. You can download it from the official Python website.
Check your installation by opening a terminal and running:
python --version
# or
python3 --version
You should see something like Python 3.x.x.
Step 2: Create Your First Python File
Create a new file called hello.py with your favorite text editor:
# hello.py
print("Hello, World!")
That’s it! This single line of code will output “Hello, World!” to the console.
Step 3: Run Your Program
Open your terminal, navigate to the directory where you saved hello.py, and run:
python hello.py
# or
python3 hello.py
You should see the output:
Hello, World!
Congratulations! You’ve just written and run your first Python program! 🎉
Understanding the Code
Let’s break down what happened:
print()is a built-in Python function- It takes one or more arguments (in this case, the string “Hello, World!”)
- It outputs the arguments to the standard output (usually the terminal)
- The
# hello.pyline is a comment - it’s ignored by Python
Variations and Experiments
Try these variations to see what happens:
# Multiple print statements
print("Hello,")
print("World!")
# Printing multiple items
print("Hello,", "World!")
# Using variables
message = "Hello, World!"
print(message)
# String concatenation
print("Hello, " + "World!")
Common Issues
Python not found
If you get command not found: python, try:
- Using
python3instead ofpython - Checking your PATH environment variable
- Reinstalling Python
File not found
Make sure you’re in the correct directory where you saved hello.py.
Next Steps
Now that you’ve written your first program, here’s what to learn next:
- Variables and Data Types - Learn about strings, numbers, and other data types
- Input and Output - Get user input and format output
- Control Flow - Conditionals (if/else) and loops
- Functions - Reusable code blocks
- Modules - Using Python’s built-in libraries
Resources
Practice Exercise
Modify the Hello World program to:
- Ask for the user’s name
- Print a personalized greeting
- Example: “Hello, [Name]! Welcome to Python!”
Happy coding! 🐍