+ 1

How to write a function to return a list of numbers from 0 to 10 including both

28th Aug 2018, 9:22 AM
Prashant Balyan
Prashant Balyan - avatar
11 Answers
+ 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)].
28th Aug 2018, 11:17 AM
Anna
Anna - avatar
+ 3
# Prashant Balyan list = [] for i in range(11): list.append(i) print(list)
28th Aug 2018, 10:40 AM
Sousou
Sousou - avatar
+ 2
the range() function already does that. use range(11) to get numbers from 0 to 10
28th Aug 2018, 9:29 AM
hinanawi
hinanawi - avatar
+ 2
try this code: def h(): x=list(range(11)) return x print(h())
28th Aug 2018, 11:01 AM
Maninder $ingh
Maninder $ingh - avatar
+ 2
Use List Comprehention: print ([i for i in range (0, 11)])
28th Aug 2018, 11:33 AM
Sebastian Keßler
Sebastian Keßler - avatar
+ 2
hinanawi No, range () returns an Iterator.
28th Aug 2018, 11:42 AM
Sebastian Keßler
Sebastian Keßler - avatar
+ 1
range. or just def fkbuiltins(): a = [0,1,2,3,4,5,6,7,8,9,10] return a
28th Aug 2018, 9:40 AM
Markus Kaleton
Markus Kaleton - avatar
+ 1
thanks Sousou ! it worked 😉
28th Aug 2018, 11:02 AM
Prashant Balyan
Prashant Balyan - avatar
0
I need a list[ ]
28th Aug 2018, 10:33 AM
Prashant Balyan
Prashant Balyan - avatar
0
of range
28th Aug 2018, 10:34 AM
Prashant Balyan
Prashant Balyan - avatar
0
Prashant Balyan range() does return a list
28th Aug 2018, 10:34 AM
hinanawi
hinanawi - avatar