DEV Community

John Mark Bulabos
John Mark Bulabos

Posted on • Updated on

Second Steps in Python: Lists, Loops, and a Little Bit of Lunacy

Welcome back, my delightful dummies! Hope you didn’t get too tangled up in the Python jungle while I was away. But if you did, fear not! Your loyal guide is here with a proverbial machete to hack through the thick foliage of confusion.

Today, we're going to expand our Python vocabulary with Lists and Loops, words that might strike fear into the hearts of non-coders (and some coders, too), but are actually about as scary as a feathered boa.

1. Lists – More Organized than Your Sock Drawer

Lists in Python are like the Swiss Army knives of the programming world – handy little tools that can store a mix of different items. A list is a collection of items that are ordered and changeable, kind of like your mood on a Monday morning, but more predictable.

Here's how you make a list:

my_list = ["apple", "banana", "cherry"]
Enter fullscreen mode Exit fullscreen mode

Congratulations! You just created a fruit salad in code form.

2. Loops – Dizziness Guaranteed

Loops are the treadmill of the Python world. They keep going until they’re told to stop (or they hit an error, kind of like tripping over your own shoelaces). In Python, we have two types of loops: for loops and while loops.

A for loop is like saying, "For every item in my grocery list, put it in the shopping cart". Here's a quick example:

for fruit in my_list:
  print(fruit)
Enter fullscreen mode Exit fullscreen mode

A while loop, on the other hand, keeps running as long as a certain condition is True. Think of it as a toddler repeatedly asking "why?" until you run out of answers (or patience).

i = 1
while i < 6:
  print(i)
  i += 1
Enter fullscreen mode Exit fullscreen mode

So now you’ve run a couple of laps around loops. Don’t worry about the dizziness; it’s part of the fun!

3. Diving Deeper

Remember, Rome wasn't built in a day, and neither are Python skills. This is a journey, not a sprint, unless you're running loops (get it?). Your Python prowess will grow with practice. Remember, even a fully-grown Python starts out as a small hatchling. And don’t forget: bugs are not just pests; they’re opportunities to learn and grow.

Until Next Time…

Well, dummies, that brings us to the end of our second Python adventure. Next time, we'll take a plunge into the exotic seas of Functions and Conditionals. Will it be a cool, refreshing dip or more like belly-flopping from the high dive? Only one way to find out.

In the meantime, practice your loops, lists, and don't forget to eat your fruit salad (you know, the one we made in code). Remember, the key to mastering Python is repetition. And fruit. Probably.


Did you enjoy the adventure? Share it with your tribe, leave a comment, or tell your cat about it. She might not care, but at least you'll feel heard. Don't forget to subscribe for more Python escapades from your favorite dummy!

P.S. As always, I must remind you that any resemblance to actual Python snakes is purely coincidental. No dummies, or snakes, were subjected to any treadmill or high dive shenanigans during the writing of this guide.

The fun doesn't end here. I have loads more humor, quirkiness, and good times waiting for you over on my YouTube channel. You won't want to miss it, trust me. Click PAIton and Crossovers to check it out and continue the fun journey with me.

Top comments (0)