Q:

do an "abstract" loop in python

Suppose I want to compute for n, print all a_1  +a_2 + ... + a_n where a_i are natural numbers less than n.
In the case n is "small" (for example n = 3), I use the following codes.
from itertools import product
n=3
for a_1,a_2,a_3 in product(range(n),repeat=n):
    print a_1+a_2+a_3

But if n is "large", say n = 10, I need type 
from itertools import product
n=10
for a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8,a_9,a_10 in product(range(n),repeat=n):
    print a_1+a_2+a_3+a_4+a_5+a_6+a_7+a_8+a_9+a_10

If I want to compute n = 100, this type will be very terrible! Do we have any other method? 

A:

Don't unpack the tuple:
for t in product(range(n), repeat=n):
    print sum(t)

By using a variable, you are implying you don't know how big the tuple will be, and therefore can't meaningfully unpack it. Your code will have to adjust accordingly.

