Setting Up Python
Setting up Python is straightforward. Here's how to get started:
Installing Python:
- Visit python.org and download the latest version
- Run the installer (check "Add Python to PATH" on Windows)
- Verify installation:
python --version
Running Python Code:
Option 1: Interactive Mode (REPL)
- Open terminal/command prompt
- Type
pythonorpython3 - Type code directly and see results
Option 2: Script Files
- Create a file with .py extension
- Run with:
python filename.py
Option 3: IDE/Editor
- VS Code: Free, popular, great Python extension
- PyCharm: Full-featured Python IDE
- Jupyter Notebook: Great for data science
Virtual Environments: Keep project dependencies isolated:
code
python -m venv myenv
source myenv/bin/activate # Linux/Mac
myenv\Scripts\activate # WindowsCode Examples
Your First Scriptpython
# hello.py - Your first Python script
# Print a greeting
print("Hello, Python!")
# Get user input
name = input("What's your name? ")
print(f"Nice to meet you, {name}!")
# Basic calculation
age = int(input("What's your age? "))
future_age = age + 10
print(f"In 10 years, you'll be {future_age}!")
# Running this script:
# python hello.pySave this code as hello.py and run it with 'python hello.py' in your terminal.
Quick Quiz
1. What file extension do Python scripts use?
Was this lesson helpful?