So far we’ve worked with single variables, like a name to say “hello” to or a nautical-themed object to point out. In this program, we want to keep track of one or more foods that we will store in a list, a variable that can hold any number of items. We use lists all the time in real life. Maybe it’s your top-five favorite songs, your birthday wish list, or a bucket list of the best types of buckets.
In this chapter, we’re going on a picnic, and we want to print a list of items to bring along. You will learn to
- Write a program that accepts multiple positional arguments
- Use if, elif, and else to handle conditional branching with three or more options
- Find and alter items in a list
- Sort and reverse lists
- Format a list into a new string
The items for the list will be passed as positional arguments. When there is only one item, you’ll print that: $ ./picnic.py salad You are bringing salad. |
|