惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
About on SuperTechFans
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog RSS Feed
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
雷峰网
雷峰网
罗磊的独立博客
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LangChain Blog
人人都是产品经理
人人都是产品经理
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
P
Proofpoint News Feed
The Cloudflare Blog
D
Docker
大猫的无限游戏
大猫的无限游戏

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Python Day Three – Lists, Indices, and Packing Your Virtu...
Bonface Thuo · 2026-05-29 · via DEV Community

Welcome back to Day 3, Python dynamic duo! 🚀 If you survived Day 2, you now know how to create variables and throw strings, integers, floats, and booleans into their own little cardboard boxes. 📦
But what happens when you’re building a game and your character needs an inventory? Or you're making a shopping list app? Creating 50 different variables like item1, item2, item3 will make you want to throw your router out the window. 🪟💻
Today, we are leveling up our storage game. We are moving out of single cardboard boxes and packing a Virtual Backpack: Enter Lists! 🎒🎉

🎒 What is a List?

In Python, a List is a data structure used to store a collection of items in one single variable. Think of it like a backpack where you can stuff multiple things inside, keep them in a specific order, and pull them out whenever you need them.
Creating a list is simple. You use square brackets [] and separate your items with commas:

# Packing our survival backpack 🗺️
backpack = ["map", "flashlight", "water bottle", "protein bar"]

print(backpack) 
# Prints: ['map', 'flashlight', 'water bottle', 'protein bar']

Enter fullscreen mode Exit fullscreen mode

The coolest part? Python lists don’t care what you put inside. You can mix strings, integers, and booleans all in one single backpack (though usually, it makes the most sense to keep similar things together).

🤯 The First Rule of Coding Club: We Start Counting at Zero!
Here is where programming turns your brain upside down. 🧠🙃

If I asked you what the first item in our backpack list is, you’d logically say "map". And you'd be right in human language. But in Python-speak, computer memory starts counting at 0.

This is called Indexing.

To pull a specific item out of your backpack, you write the name of the list followed by the item's position (index) inside square brackets:

backpack = ["map", "flashlight", "water bottle", "protein bar"]

# Pulling out the items using their index 🔍
print(backpack[0])  # Prints: map (The absolute first item!)
print(backpack[1])  # Prints: flashlight (The second item!)
print(backpack[3])  # Prints: protein bar

Enter fullscreen mode Exit fullscreen mode

⚠️ Tantrum Alert: If you try to print backpack[4], Python will immediately crash and scream:

IndexError: list index out of range.

Enter fullscreen mode Exit fullscreen mode


python
Why? Because there is no 5th item! Always remember: if your list has 4 items, the indices go from 0 to 3.

🛠️ Modifying the Backpack (List Methods)

The best thing about a backpack is that it isn’t glued shut. You can add things to it, change things inside it, or chuck things away when you don't need them anymore.

Here are the three most common magic spells you’ll use with lists:

1. Changing an item (Reassignment)
Did your flashlight break? Let's swap it out for a laser pointer:

backpack[1] = "laser pointer"
print(backpack)
# Prints: ['map', 'laser pointer', 'water bottle', 'protein bar']

Enter fullscreen mode Exit fullscreen mode

2. Adding an item (.append())
Found some gold coins on the floor? Let’s stuff them into the bottom of the backpack using .append():

backpack.append("gold coins")
print(backpack)
# Prints: ['map', 'laser pointer', 'water bottle', 'protein bar', 'gold coins']

Enter fullscreen mode Exit fullscreen mode

3. Removing an item (.remove())
Got hungry and ate the protein bar? We can remove it by name:

backpack.remove("protein bar")
print(backpack)
# Prints: ['map', 'laser pointer', 'water bottle', 'gold coins']

Enter fullscreen mode Exit fullscreen mode

Thats a wrap for the day ⏱️

🚀 Today's Challenge 🏆

Time to put your virtual backpack to the test!

Create a list called gaming_squad containing the names of 3 of your friends (or fictional characters).

Print out the second person in that list (Remember the zero-counting rule! 👀).

Use .append() to add a 4th teammate to the squad.

Print the final list to the console to make sure they made the cut.

Drop your code or your squad lineup in the comments below! Are you starting to see how powerful these boxes can get? Tomorrow, we are looking at Tuples—which are basically lists that have been permanently superglued shut. 🔒

See you on Day 4! 🐍💻👇