Monday, August 27, 2012

printing first n natural numbers starting from 0 in python


def ranarr(len):
    arr=[]
    for i in range(0,len):
        arr.append(i)
        print(i)
    return arr

print(ranarr(10))



result :

0
1
2
3
4
5
6
7
8
9
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

No comments:

Post a Comment