+ 1
How to write a function to return a list of numbers from 0 to 10 including both
11 Réponses
+ 6
hinanawi, a range returns a range 😉
If you type print(type(range(11))), the result will be <class 'range'>, not <class 'list'>.
You can convert it to a list by using list(range(11)) (as already mentioned) or you can use a list comprehension: [i for i in range(11)].
+ 3
# Prashant Balyan
list = []
for i in range(11):
list.append(i)
print(list)
+ 2
the range() function already does that. use range(11) to get numbers from 0 to 10
+ 2
try this code:
def h():
x=list(range(11))
return x
print(h())
+ 2
Use List Comprehention:
print ([i for i in range (0, 11)])
+ 2
hinanawi No, range () returns an Iterator.
+ 1
range. or just
def fkbuiltins():
a = [0,1,2,3,4,5,6,7,8,9,10]
return a
+ 1
thanks Sousou ! it worked 😉
0
I need a list[ ]
0
of range
0
Prashant Balyan range() does return a list