On Mon, Jan 5, 2009 at 14:19, vanam <raghavendra.gv.va...@gmail.com> wrote:
> I am trying tounderstand the below lines of code but of no avail.

Python can loop over many types of sequences.. This can be a list,
tuple or string and in your example a list.

> a = ["cat", "window","defenestrate"]
> for x in a:
>      print x, len(x)
> i cant understand what x is doing here and what is the purpose of it
> can anyone help me out here?

In the example for every loop x becomes 1 of the values in the list (3
in total). So in the first loop it has value "cat", second  "window"
and third "defenestrate".

How loops work in python is part of most python beginners guides, for
example "Dive into Python" [1].

Greets
Sander

[1] http://diveintopython.org/toc/index.html
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to