Python Get Started
Install Python and set up your development environment to start coding
š Getting Started with Python
To start programming in Python, you need to install Python on your computer. Python is available for Windows, macOS, and Linux. Let's get you set up and ready to code!
šÆ What You'll Learn
- How to install Python on different operating systems
- How to verify your Python installation
- How to run your first Python program
- Recommended code editors and IDEs
- Setting up a virtual environment
Check if Python is Already Installed
Many computers come with Python pre-installed. Let's check if you already have Python on your system.
Windows Instructions:
- Press Win + R to open the Run dialog
-
Type
cmdand press Enter to open Command Prompt - Type the following command and press Enter:
python --version
Expected Output:
If Python is installed, you'll see something like
Python 3.11.0
If not installed:
You'll see an error message like
'python' is not recognized as an internal or external command
macOS Instructions:
- Press Cmd + Space to open Spotlight
-
Type
Terminaland press Enter - Type the following command and press Enter:
python3 --version
Note:
On macOS, use
python3
instead of
python
to ensure you're using Python 3.x
Expected Output:
Python 3.11.0
or similar
Linux Instructions:
- Open Terminal (usually Ctrl + Alt + T )
- Type the following command and press Enter:
python3 --version
Note: Most Linux distributions come with Python pre-installed
Expected Output:
Python 3.11.0
or similar
Download and Install Python
If Python is not installed on your system, follow these steps to install it:
Visit Python.org
Go to the official Python website: https://www.python.org/downloads/
The website automatically detects your operating system and shows the appropriate download button.
Download the Installer
Click the "Download Python" button to download the latest version for your operating system.
Run the Installer
Windows
-
Run the downloaded
.exefile - Important: Check "Add Python to PATH"
- Click "Install Now"
macOS
-
Run the downloaded
.pkgfile - Follow the installation wizard
- Enter password when prompted
Linux
sudo apt update
sudo apt install python3 python3-pip
Verify Installation
After installation, verify that Python is installed correctly:
# Check Python version
python --version
# Check pip (package installer) version
pip --version
Your First Python Program
Now that Python is installed, let's write and run your first Python program!
Method 1: Interactive Shell
The Python interactive shell (REPL) allows you to run Python code line by line.
python
and press Enter
>>>
>>> print("Hello, World!")
Hello, World!
>>> print("Welcome to Python!")
Welcome to Python!
>>> 2 + 3
5
>>> name = "Alice"
>>> print(f"Hello, {name}!")
Hello, Alice!
>>> exit() # To quit
Method 2: Python File
For longer programs, create a Python file (.py extension).
# My first Python program
print("Hello, World!")
print("This is my first Python program!")
# Variables and basic operations
name = "Python Learner"
age = 25
favorite_number = 7
print(f"My name is {name}")
print(f"I am {age} years old")
print(f"My favorite number is {favorite_number}")
# Simple calculation
result = favorite_number * 2
print(f"{favorite_number} multiplied by 2 equals {result}")
# Fun fact
print("Did you know? Python was named after Monty Python's Flying Circus!")
python hello.py
Recommended Code Editors and IDEs
While you can write Python code in any text editor, using a proper code editor or IDE will make your coding experience much better.
Visual Studio Code
Best for: Beginners and professionals
- Free and open-source
- Excellent Python extension
- Built-in terminal
- Git integration
PyCharm
Best for: Professional development
- Powerful Python IDE
- Advanced debugging
- Code refactoring tools
- Free Community Edition
Jupyter Notebook
Best for: Data science and learning
- Interactive coding environment
- Great for data analysis
- Supports visualizations
- Web-based interface
Sublime Text
Best for: Fast and lightweight editing
- Very fast and responsive
- Multiple cursors
- Powerful search and replace
- Cross-platform
šļø Practice Exercise: Test Your Setup
Try creating and running this simple program to test your setup:
import sys
import datetime
print("š Python Setup Test")
print("=" * 30)
print(f"Python version: {sys.version}")
print(f"Current date: {datetime.date.today()}")
print(f"Platform: {sys.platform}")
# Test basic operations
numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print(f"Sum of {numbers} = {total}")
# Test string operations
name = input("What's your name? ")
print(f"Hello, {name}! Welcome to Python programming!")
print("\nā
If you can see this message, your Python setup is working correctly!")
š Congratulations! You're Ready to Code
You now have Python installed and ready to use. Here's what you should do next:
Learn Python Syntax
Understand the basic rules and structure of Python code
Practice Coding
Start with simple programs and gradually build complexity
Set Up Your IDE
Configure your development environment for better productivity