Q:

Program not showing all values in for loop

i have started learning python and i have problem.
I learn for loops and i am a little bit confused.
I tried this:
for i in range(0,12,3):
    print(i)

Why program is not showing 12 value?
In other languages e.g java it works.
Anyone help?

A:

The upper bound of range is non-inclusive. From the documentation:

For a positive step, the contents of a range r are determined by the formula r[i] = start + step*i where i >= 0 and r[i] < stop.

Read more here.

Java's equivalent:
IntStream.range(0, 12 / 3).map(x -> x * 3).forEach(System.out::print);

Also does not include the upper bound. This will also print 0 3 6 9, not 12.

