Exercise 42
Doing Things to Lists
You have learned about lists. When you learned about while-loops
, you “appended” numbers to the end of a list and printed them out. There were also Study Drills where you were supposed to find all the other things you can do to lists in the Python documentation. That was a while back, so review those topics if you do not know what I’m talking about.
Found it? Remember it? Good. When you did this, you had a list, and you “called” the function append()
on it. However, you may not really understand what’s going on, so let’s see what we can do to lists.
When you write mystuff.append('hello')
, you are actually setting off a chain of events inside Python to cause something to happen to the mystuff
list. Here’s how ...
Get Learn Python the Hard Way: A Deceptively Simple Introduction to the Terrifyingly Beautiful World of Computers and Data Science, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.