Python Tutorial — Learn Python Step by Step
Key takeaway: Master Python programming from scratch — variables, loops, functions, OOP, file handling, and libraries — with clear human-readable explanations and runnable code examples.
Install Python on Ubuntu / Linux
Most Linux distributions include Python 3 by default. Ubuntu 20.04+ ships with Python 3.8+. Here's how to check, install, or upgrade Python on Ubuntu and Debian-based systems.
Check if Python is Already Installed
# Check Python 3 version
python3 --version
# Output: Python 3.10.12 (or similar)
# Check pip
pip3 --version
# If not installed: "pip3: command not found"Install or Update Python 3
# Update package list
sudo apt update
# Install Python 3 and pip
sudo apt install python3 python3-pip python3-venv
# Verify
python3 --version
pip3 --version
# Install a specific version (e.g., 3.12) using deadsnakes PPA
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12 python3.12-venv python3.12-devSet Up a Virtual Environment
# Create a project directory
mkdir myproject && cd myproject
# Create virtual environment
python3 -m venv venv
# Activate it
source venv/bin/activate
# Your prompt changes: (venv) user@machine:~/myproject$
# Now install packages into this isolated environment
pip install flask requests pandas
# Deactivate when done
deactivateVirtual environments are essential on Linux because system Python packages are managed by apt. Installing with pip globally can conflict with system packages. Always use a venv for project dependencies.
First Program
#!/usr/bin/env python3
# The shebang line above lets you run the script directly: ./hello.py
import platform
print(f"Hello from {platform.system()} {platform.release()}!")
print(f"Python {platform.python_version()}")
print("Installation complete!")$ python3 hello.py Hello from Linux 5.15.0-91-generic! Python 3.10.12 Installation complete!
Make Scripts Executable
# Make a Python script executable directly
chmod +x hello.py
# Now you can run without typing python3
./hello.py
# The #!/usr/bin/env python3 shebang tells the OS which interpreter to useTroubleshooting
| Problem | Solution |
|---|---|
pip3: command not found | sudo apt install python3-pip |
externally-managed-environment error (Ubuntu 23.04+) | Always use a virtual environment: python3 -m venv venv |
| Need newer Python than apt provides | Use deadsnakes PPA: sudo add-apt-repository ppa:deadsnakes/ppa |
ModuleNotFoundError after install | Ensure you installed the package in the active venv, not globally |
| Permission denied | Use --user flag or activate a virtual environment |
Python Programming Tutorial — Learn Python in a practical, step-by-step way. According to the official Python documentation, Python emphasizes code readability and simplicity, making it ideal for beginners.
Related tools: Python Online Compiler | Python Examples | JavaScript Tutorial | Java Tutorial
Python Career & Learning Guide
Python is the world's most popular programming language for beginners, data science, AI/ML, web development, and automation. This tutorial teaches Python step-by-step with clear explanations and runnable code examples in our free Python Compiler.
Why Learn Python in 2026?
- #1 Most Popular Language: Ranked first on TIOBE, Stack Overflow, and GitHub.
- AI and Data Science: The primary language for machine learning (TensorFlow, PyTorch, scikit-learn) and data analysis (Pandas, NumPy).
- Web Development: Django and Flask power scalable backends at companies like Instagram and Spotify.
- Automation & Scripting: Automate files, emails, web scraping, and data processing in minutes.
Python vs Other Languages
| Feature | Python | Java | JavaScript | C++ |
|---|---|---|---|---|
| Syntax | Very clean, readable | Verbose | Moderate | Complex |
| Typing | Dynamic, strong | Static, strong | Dynamic, weak | Static, strong |
| Best For | AI/ML, Data, Web | Enterprise, Android | Web Frontend/Backend | Systems, Games |
| Learning Time | 2–4 weeks basics | 4–6 weeks basics | 3–4 weeks basics | 8–12 weeks basics |
Frequently Asked Questions
Do I need prior programming experience to learn Python?
No! Python is specifically designed to be beginner-friendly. This tutorial starts from zero and builds up gradually.
Which Python version should I use?
Python 3.10+ is recommended. All examples in this tutorial use Python 3 syntax.
Is this Python tutorial completely free?
Yes, 100% free with no registration or sign-up required. Access all lessons and code examples anytime.