O'Reilly logo

Head First Learn to Code by Eric Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. 4 lists and iteration: Providing Some Structure

Image

There’s more to data types than numbers, strings, and Booleans. So far you’ve been writing Python code using primitive types—those floats, integers, strings, and of course Booleans—with values like 3.14, 42, "hey, it’s my turn", and True. And you can do a lot with primitives, but at some point you’ll want to write code that deals with lots of data—say, all the items in a shopping cart, the names of all the notable stars, or an entire product catalog. For that we need a little more ummph. In this chapter we’re going to look at a new type, called a list, which can hold a collection of values. With lists, you’ll be able to provide some structure for your data, rather than just having a zillion variables floating around your code holding values. You’re also going to learn how to treat all those values as a whole as well as how to iterate over each item in a list using that for loop we mentioned in the last chapter. After this chapter, your ability to deal with data is going to grow and expand.

Image

Can you help Bubbles-R-Us?

Check out the Bubbles-R-Us company. Their tireless research makes sure bubble wands and machines everywhere blow the best bubbles. Today they’re testing the “bubble factor” of several different formulations ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required