The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.python
From: Steven Bethard <steven.beth...@gmail.com>
Date: Sat, 26 May 2007 13:38:44 -0600
Local: Sun, May 27 2007 5:38 am
Subject: Re: ten small Python programs
Steve Howell wrote: Very cool! Do you mind putting this up on the Wiki somewhere so that we > I've always thought that the best way to introduce new > programmers to Python is to show them small code > examples. > When you go to the tutorial, though, you have to wade > Below is my attempt at generating ten fairly simple, can link to it more easily? Maybe something like: http://wiki.python.org/moin/SimplePrograms <nitpick> http://www.python.org/dev/peps/pep-0008/ > class ShoppingCart: I think boughtItems() is probably not a good example of Python code > def __init__(self): self.items = [] > def buy(self, item): self.items.append(item) > def boughtItems(self): return self.items > myCart = ShoppingCart() > myCart.buy('apple') > myCart.buy('banana') > print myCart.boughtItems() since in this case, you should probably just write ``my_cart.items``. Maybe it should define ``__len__`` instead? Or maybe something like:: def select_items(self, prefix): STeVe You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||