# [Tutor] Re: Tutor digest, Vol 1 #306 - 8 msgs

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Sun, 14 May 2000 01:12:37 -0700 (PDT)

```> Hours", and was doing quite well until chapter 6. Bogged down in tuples,
> with lists next. This is my first attempt at programming, and find this a
> bit much. How does one remember the syntax, functions, indentations, etc?

If this is your first time encoutering lists and tuples, then it'll take a
little while to understand their usage and usefulness.  Practice and
familiarity definitely help, but I wouldn't call it all mechanical syntax
--- there's something conceptually interesting about having a list.  A
list is a collection of data.  You might be familiar with shopping lists,
and in python, we'd represent that as a list of strings, like this:

shopping_list = ['apple', 'ketchup', 'cottage cheese']

and if I wanted to get the first item of my strange diet, I'd say

shopping_list[0]

It might feel weird to ask for the zeroth thing on your list.  That part
is a little hard to explain for me, so try to put that on the back burner
for now.

What may surprise you, though, is that you've already been introduced to a
single variables, like numbers and strings.

book = "Teach Yourself Python in 21 Days"
day = 24

But let's take a closer look at that 'book'.  First of all, let's take a
look at how long it is.

len(book)

Python says "32".  But 32...what?  32 characters!  That is, a string can
be thought of as a collection (or, as your book calls them, sequences) of
characters.  It makes sense that a word is made up of letters.  Let's try
to make the analogy between lists and strings a little more clear.

book[0]

will say 'T'.  What we've done is ask python, What is the first character
in our sentence "Teach Yourself Python in 21 Days"?

If we wanted to see every other letter in our sentence, we could try
something like:

print book[0], book[2], book[4], book[6],

but already it's getting wearisome to keep on writing book[some even
number] in there.  That's why we use something like a loop to do things
with these list-like things:

length = len(book)
position = 0
while position < length:
print book[position],
position = position + 2

(That comma at the end of the print statement is intentional.  See what
happens if you take it out)

So strings, lists, and tuples are all sequence structures.  You can ask
what they contain at a specific location, and this is called
"subscripting".  Start slow, explore what you can do, and experiment with
python a little more --- make sure that things make sense, and if they
don't, feel free to ask for clarification.  Hope this helps!

```