Every week, I make a visual map of my “learning life” — I share what I learn, how I learned it, and my learning doodle.
As much as I wanted to skip ahead to building cool projects in Week 1, I realized how much I needed to learn the basics. So the goal of Week 2 was honing in on IF statements, WHILE loops, FOR loops, and lists.
🔨 WHAT I LEARNED
The biggest thing I learned this week were FOR loops. If you’ve never seen a FOR loop, it can look kind of like this:
x = ['a','b','c','d']
y = []
for i in x:
add = i + 'value'
y.append(add)
print(y)
While they were confusing at first, I started thinking of FOR loops kind of like doing laundry.
Let me explain.
Step 1: What’s in your Laundry Basket
Imagine that you have a laundry basket full of freshly cleaned clothes — a shirt, pants, shorts, and a sweater. And you have an empty closet where you will hang your clothes. These are your two lists — the basket filled with clothes and an empty closet.
laundry_basket = ['Shirt','Pants','Shorts','Sweater']
closet = []
Step 2: “Loop” over your clothing
Then you’ll want to take each item out of the basket one by one. The “loop” occurs when every piece of clothing in the laundry basket gets taken out and is defined as “item”, one after the other.
for item in laundry_basket
Step 3: Hang each item of clothing
Next, you’ll want to put a hanger into each item:
for item in laundry_basket:
hanger = item + ' in hanger'
Step 4: “Append” each item into the closet
Once it’s in the hanger, you’ll place your hanger in the closet (or append it into the closet).
for item in laundry_basket:
hanger = item + ' in hanger'
closet.append(hanger)
Step 5: Your closet is full of clothes
And once you’re all done, you’ll take one final look at your closet and admire all your hard work.
laundry_basket = ['Shirt','Pants','Shorts','Sweater']
closet = []
for item in laundry_basket:
hanger = item + ' in hanger'
closet.append(hanger)
print(closet)
### Result:
### closet = ['Shirt in hanger','Pants in hanger','Shorts in hanger','Sweater in hanger']
👩🏫 HOW I LEARNED
To learn the basics, I used Mosh Hamedani’s free “Python Tutorial — Python Full Course for Beginners”. Out of the 6 hour video, I watched up to hour 2:02:00. Highly recommend his Youtube if you’re getting started with Python — he explained concepts so clearly and he had a very chill energy.
✍️ MY LEARNING DOODLE
Very small picture of my doodle because it didn’t turn out well. I repeat, I’m a bad drawer.
👾 CHECK OUT THE CODE
Github here: https://github.com/adriana-vanegas/python-learning/tree/main/week_two_basics
Excellent posts. Please keep sharing
Thanks Ali, hope they’re helpful!