0

how can i make a list of number form 1 to a certain number? i want to make a script that can do things like below:

number=20
list=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]

i don't know how do make this happens. is there certain function for auto produce the list, i am now typing it manually? i've try to google it, but most the answers are about seperating a number and make a list.like this

a='1234'
a.split(' ')
[1,2,3,4]
Chris Chen
  • 47
  • 1
  • 5

1 Answers1

1

For Python 2,

l = range(1, number + 1)

In Python 3, range returns an iterable sequence so if you really need a list, you can convert it

l = list(range(1, number + 1))
msitt
  • 1,237
  • 12
  • 27