pain

Michael Hoffman cam.ac.uk at mh391.invalid
Wed Aug 3 19:21:44 CEST 2005


Mage wrote:

> Look at this tutorial from java.com:
> 
> public class BasicsDemo {
>    public static void main(String[] args) {
>        int sum = 0;
>        for (int current = 1; current <= 10; current++) {
>            sum += current;
>        }
>        System.out.println("Sum = " + sum);
>    }
> }

And then you have to compile it and set up your classpath...

> It is "print sum(range(11))" in python.

I would have used print sum(xrange(11)) myself. This probably has almost 
zero measurable performance impact, but I think using xrange() instead 
of range() is usually a good habit. As you know, xrange() generates ints 
as it is called rather than all at once, which can be quite helpful with 
large ranges.

 > I suggest you to feel lucky if you may use python at your work.

Every day.
-- 
Michael Hoffman



More information about the Python-list mailing list