explainx.ainewsletter3.5k
TrendingNewsPathwaysSkills
Pricing
explainx.ai

Upskill in AI — 16 free pathways, live workshops & bootcamps, and 50+ courses from practitioners. Plus the skills, tools, and MCP servers to practice on.

follow us

custom AI agents

[email protected]

get started

Find your pathTake Free Evaluation

learn

pathways — start freeworkshopsbootcampscoursescertificationsmock testsexplainx universitycorporate traininglearn skills & mcp

discover

skillsmcp serversexplainx mcptoolsagentsllmsdesignsagi trackerranks

company

aboutvisionmissionteaminstructorscommunityhackathonscareers

content

daily AI newsstate of AI — live resultsblogreleasespromptsgeneratorsresource librarydemofor LLMs

solutions

all solutionsdeveloper upskillingmarketing upskillingproduct manager upskillingleadership upskilling

More from us

InfloqInfluencer marketingBgBlurPrivacy-first blurOlly SocialSocial AI copilotCeptoryVideo intelligenceBgRemoverBackground removal

newsletter · weekly

Get AI news, tools, and insights in your inbox.

supportprivacytermsdata rightssubmission guidelines

© 2026 AISOLO Technologies Pvt Ltd

On this page

  • Step 1: Install Python
  • Step 2: Install a code editor
  • Step 3: Write and run your first script
  • The core concepts
  • Step 4: Set up a virtual environment
  • Step 5: Install packages with pip
  • Step 6: A real beginner project
  • Common beginner mistakes
  • What to learn next
← Back to blog

explainx / blog

Python Basics: How to Install Python and Write Your First Script (2026 Guide)

Python explained from scratch: how to install it on Mac and Windows, how to write and run your first script, and the core concepts — variables, functions, loops, and pip — that you'll use in every Python project.

Jun 27, 2026·4 min read·Yash Thakker
PythonBeginner GuideProgrammingDeveloper ToolsSetup Guide
go deep
Python Basics: How to Install Python and Write Your First Script (2026 Guide)

Python is the most-used programming language in AI, data science, and automation. It's also widely considered the easiest language to learn first — the syntax is close to plain English and the feedback loop is immediate.

This guide gets you from nothing to a working Python setup with a real script in under 30 minutes.

Install Python and write your first scripts — full beginner walkthrough.

Step 1: Install Python

macOS

Check if Python is already installed:

bash
python3 --version

If you see Python 3.10 or higher, you can skip to Step 2. If not, or if you want the latest version:

Option A — Homebrew (recommended):

bash
brew install python

If you don't have Homebrew, install it first:

bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Option B — Official installer:

  1. Go to python.org/downloads
  2. Download the latest Python 3.13.x macOS installer
  3. Run the .pkg file and follow the installer

After installation:

bash
python3 --version

You should see Python 3.13.x.

Windows

  1. Go to python.org/downloads
  2. Download Python 3.13.x (Windows installer)
  3. Run the installer
  4. Important: Check the box that says "Add Python to PATH" before clicking Install

Open Command Prompt or PowerShell and verify:

bash
python --version

On Windows, the command is python (not python3). On Mac/Linux, use python3 to avoid accidentally using an old Python 2 installation.


Step 2: Install a code editor

If you haven't already, install Cursor or VS Code. Both have excellent Python support.

In VS Code or Cursor, install the Python extension by Microsoft — it adds syntax highlighting, autocomplete, and the ability to run Python files directly in the editor.


Step 3: Write and run your first script

Create a folder for your Python projects:

bash
mkdir python-projects
cd python-projects

Create your first Python file:

bash
# Mac/Linux
touch hello.py

# Windows
type nul > hello.py

Open hello.py in your editor and type:

python
print("Hello, Python!")

name = "Alice"
print(f"Hello, {name}!")

numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print(f"The sum of {numbers} is {total}")

Run it:

bash
# Mac/Linux
python3 hello.py

# Windows
python hello.py

Output:

snippet
Hello, Python!
Hello, Alice!
The sum of [1, 2, 3, 4, 5] is 15

The core concepts

Variables

Variables store values. No type declaration needed — Python figures it out:

python
name = "Alice"           # string
age = 28                 # integer
height = 5.7             # float
is_student = True        # boolean

print(name, age, height, is_student)

Strings and f-strings

python
first = "Alice"
last = "Smith"

# Concatenation (old way)
full = first + " " + last

# f-strings (modern way — preferred)
full = f"{first} {last}"
greeting = f"Hello, {first}! You are {age} years old."

print(greeting)

Lists

python
fruits = ["apple", "banana", "cherry"]

print(fruits[0])         # apple — indexing starts at 0
print(fruits[-1])        # cherry — last item

fruits.append("mango")   # add to end
fruits.remove("banana")  # remove by value

print(len(fruits))       # 3 — number of items

Dictionaries

python
person = {
    "name": "Alice",
    "age": 28,
    "city": "London"
}

print(person["name"])    # Alice
person["job"] = "Engineer"  # add a new key
print(person)

If / else

python
age = 20

if age >= 18:
    print("You are an adult")
elif age >= 13:
    print("You are a teenager")
else:
    print("You are a child")

For loops

python
fruits = ["apple", "banana", "cherry"]

for fruit in fruits:
    print(f"I like {fruit}")

# Loop over a range of numbers
for i in range(5):
    print(i)   # prints 0, 1, 2, 3, 4

# Loop with index
for i, fruit in enumerate(fruits):
    print(f"{i}: {fruit}")

Functions

python
def greet(name):
    return f"Hello, {name}!"

def add(a, b):
    return a + b

message = greet("Alice")
print(message)

result = add(3, 4)
print(result)    # 7

Functions with default parameters:

python
def greet(name, greeting="Hello"):
    return f"{greeting}, {name}!"

print(greet("Alice"))           # Hello, Alice!
print(greet("Bob", "Hi"))       # Hi, Bob!

Step 4: Set up a virtual environment

A virtual environment isolates your project's packages from the rest of your system. Always use one.

Create a virtual environment in your project folder:

bash
# Mac/Linux
python3 -m venv venv

# Windows
python -m venv venv

Activate it:

bash
# Mac/Linux
source venv/bin/activate

# Windows (Command Prompt)
venv\Scripts\activate.bat

# Windows (PowerShell)
venv\Scripts\Activate.ps1

When activated, your terminal prompt shows (venv) at the start:

snippet
(venv) user@machine:~/python-projects$

Everything you install now goes into this environment, not your system Python.

To deactivate when you're done:

bash
deactivate

Step 5: Install packages with pip

pip is Python's package installer. With your virtual environment active:

bash
pip install requests

This installs the requests library — the standard way to make HTTP calls in Python.

Test it:

python
import requests

response = requests.get("https://api.github.com")
print(response.status_code)   # 200
print(response.json()["current_user_url"])

Save your dependencies so others can replicate your environment:

bash
pip freeze > requirements.txt

To install from a requirements.txt on a new machine:

bash
pip install -r requirements.txt

Step 6: A real beginner project

Build a script that fetches today's weather for any city using a free API.

Install the requests library if you haven't:

bash
pip install requests

Create weather.py:

python
import requests

def get_weather(city):
    url = f"https://wttr.in/{city}?format=j1"
    response = requests.get(url)
    
    if response.status_code != 200:
        return f"Could not fetch weather for {city}"
    
    data = response.json()
    current = data["current_condition"][0]
    
    temp_c = current["temp_C"]
    feels_like = current["FeelsLikeC"]
    description = current["weatherDesc"][0]["value"]
    
    return f"{city}: {description}, {temp_c}°C (feels like {feels_like}°C)"

cities = ["London", "New York", "Tokyo", "Mumbai"]

for city in cities:
    print(get_weather(city))

Run it:

bash
python3 weather.py

You're fetching live data, parsing JSON, and printing formatted output — with less than 25 lines of code.


Common beginner mistakes

Not activating the virtual environment. If you install packages and they "don't work", check that (venv) is showing in your terminal prompt.

Using python vs python3. On Mac/Linux, always use python3. On Windows, python usually points to Python 3 if you installed it correctly.

Indentation errors. Python uses indentation (spaces) instead of curly braces to structure code. Mixing tabs and spaces causes errors. Use spaces consistently (4 spaces per indent is the standard).

Forgetting to save the file. Python runs whatever is on disk, not what's in your editor. Save before running.


What to learn next

  • File I/O — reading and writing files with open()
  • Error handling — try / except blocks
  • List comprehensions — [x * 2 for x in numbers] — a concise way to build lists
  • Classes — object-oriented programming with class
  • Common libraries — pandas for data, flask for web APIs, anthropic for Claude AI

The Anthropic Python SDK lets you call Claude from a Python script:

bash
pip install anthropic
python
import anthropic

client = anthropic.Anthropic()

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Explain Python decorators simply."}]
)

print(message.content[0].text)

Python is the language most AI and ML work is written in — now you have the foundation to explore it.

Yash Thakker

Written by

Yash Thakker

Yash is an AI expert with over 300K learners. Join his workshops →

Related posts

Jun 27, 2026

What is Cursor? How to Build Your First HTML Project with AI (2026 Guide)

Cursor explained from scratch: how to install it, how the AI works, and how to build a real HTML page from a plain-English description. Your first AI-assisted project in under 30 minutes.

Jun 27, 2026

What is Docker? How to Build Your First Docker Image (Beginner Guide 2026)

Docker demystified: what an image is, what a container is, how a Dockerfile works, and how to build and run your first container in under 20 minutes.

Jun 27, 2026

What is Git? How to Push Your First Code to GitHub (Beginner Guide 2026)

Git explained from scratch: what it is, how to install it on Mac and Windows, and exactly how to push code to GitHub with real commands you can copy right now.