[Tutor] Request for help learning the right way to deal with listsin lists

Christopher King g.nius.ck at gmail.com
Thu Jul 15 21:47:41 CEST 2010


I will spilt it up and add comments.

Books =\ #Assign to Books
[Book('War & Peace", [3, 56, 88]), #The first is a Book named 'War & Peace'
Book("Huck Finn", [2, 5, 19])] #You use the book class twice in a row, one
for each book


On Thu, Jul 15, 2010 at 8:09 AM, Payal <payal-python at scriptkitchen.com>wrote:

> On Tue, Jul 13, 2010 at 08:35:45AM +0100, Alan Gauld wrote:
> > If the data gets more complex you could put the data into a class:
> >
> > class Book:
> >      def __init__(self, title, pages=[]):
> >          self.title = title
> >          self.pages = pages
> >
> > Books = [ Book('War & Peace", [3,56,88]),
> >               Book("Huck Finn", [2,5,19]) ]
>
> Can someone please explain the above 2 lines?
>
> > for book in Books:
> >     print book.title, book.pages
>
> With warm regards,
> -Payal
> --
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100715/66a8b759/attachment.html>


More information about the Tutor mailing list