| |
comp.lang.python |
> When you go to the tutorial, though, you have to wade > Below is my attempt at generating ten fairly simple, http://wiki.python.org/moin/SimplePrograms <nitpick> http://www.python.org/dev/peps/pep-0008/ def select_items(self, prefix): STeVe
> I've always thought that the best way to introduce new
> programmers to Python is to show them small code
> examples.
> through quite a bit of English before seeing any
> Python examples.
> representative Python programs that expose new users
> to most basic concepts, as well as the overall syntax.
can link to it more easily? Maybe something like:
Though the code should probably follow PEP 8 guidelines, e.g.
under_scores instead of camelCase for object and method names:
</nitpick>
> 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::
return [item for item in self.items if item.startswith(prefix)]