[Tutor] General design question

Alan Gauld alan.gauld at btinternet.com
Thu Jul 3 02:52:58 CEST 2008

"Paul Melvin" <paul at assured-networks.co.uk> wrote

> For example, if I generate some numbers using range the only way I 
> could
> easily sum them was to append them to a list and then call the sum 
> function,
> if I tried without the list I couldn't sum them at all.

Lots of good general answers but specifically for a range try:

>>> print sum( range(3,7) )

ie range() returns the numbers already in a list you don't
need to append them to another list.

BTW If you haven't already, take a look at my tutorial.
It compares Python to VBScript which is a modern version of Basic
It may bring back some of your old menories and help translate
those to Python.


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list