← View series: python tutorials
~/blog
Introduction to Python
Introduction
Welcome to your first Python tutorial! In this lesson, you'll learn what Python is, why it's so popular, how to set up your development environment, and write your very first Python program.
Python is one of the most popular programming languages in the world. It's used for web development, data science, artificial intelligence, automation, and much more.
What You'll Learn
- What Python is and why you should learn it
- How to install Python on your computer
- Setting up a code editor (VS Code)
- Writing and running your first Python program
- Understanding Python's philosophy
What is Python?
Python is a high-level, interpreted programming language created by Guido van Rossum in 1991. It's known for its clean syntax and readability, making it perfect for beginners.
Why Learn Python?
| Feature | Benefit |
|---|---|
| Easy to Learn | Simple syntax similar to English |
| Versatile | Web, AI, Data Science, Automation, and more |
| High Demand | One of the most sought-after skills |
| Large Community | Tons of resources and libraries |
| Cross-Platform | Works on Windows, Mac, Linux |
Installing Python
Windows
- Visit python.org
- Download the latest version (Python 3.x)
- Run the installer
- Important: Check "Add Python to PATH"
- Click "Install Now"
macOS
Python usually comes pre-installed, but we recommend installing the latest version:
# Using Homebrew (recommended)
brew install pythonLinux
Most Linux distributions come with Python pre-installed. If not:
# Ubuntu/Debian
sudo apt update
sudo apt install python3
# Fedora
sudo dnf install python3Verifying Python Installation
Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux) and type:
python --version
# Output: Python 3.x.xOr on some systems:
python3 --version
# Output: Python 3.x.xSetting Up VS Code
Visual Studio Code (VS Code) is a free, powerful code editor recommended for Python development.
Installing VS Code
- Visit code.visualstudio.com
- Download for your operating system
- Install with default settings
Installing Python Extension
- Open VS Code
- Click the Extensions icon (or press
Ctrl+Shift+X) - Search for "Python"
- Install the one by Microsoft
Your First Python Program
Now let's write your first Python program - the classic "Hello, World!" program.
Using Interactive Mode
Open your terminal and type:
python
# You'll see >>> prompt
print("Hello, World!")
# Output: Hello, World!Using a Python File
- Create a new folder for your Python projects
- Open VS Code and open that folder
- Create a new file named
hello.py - Add the following code:
# My first Python program
print("Hello, World!")
# You can print multiple things
print("Welcome to Python!")
print("This is your first program.")- Run the program:
- Press
F5or - Right-click and select "Run Python File"
- Or in terminal:
python hello.py
- Press
Expected Output:
Hello, World!
Welcome to Python!
This is your first program.
Understanding the print() Function
The print() function outputs text to the screen. It's one of the most used functions in Python.
# Basic usage
print("Hello")
# Multiple strings (automatically adds spaces)
print("Hello", "World")
# Using escape characters
print("Hello\nWorld") # \n creates a new line
print("Tab\tSpace") # \t creates a tab
# f-strings (formatted strings)
name = "Python"
print(f"Hello, {name}!")Python's Philosophy
Python has a famous philosophy called "The Zen of Python". View it by running:
import thisYou'll see principles like:
- Beautiful is better than ugly
- Explicit is better than implicit
- Simple is better than complex
- Readability counts
Summary
In this tutorial, you learned:
- ✅ What Python is and why it's popular
- ✅ How to install Python on Windows, Mac, and Linux
- ✅ How to set up VS Code for Python development
- ✅ How to write and run your first Python program
- ✅ How the print() function works
🧑💻 Practice Exercise
Create a program that prints a greeting with your name. It should output something like:
Hello, my name is [Your Name]!
I am learning Python.
Click to see solution
# My greeting program
name = "Your Name"
print(f"Hello, my name is {name}!")
print("I am learning Python.")What's Next
In the next tutorial, we'll learn about Variables and Data Types - how Python stores and manipulates different kinds of data.