How can I generate a sequence of string numbers in a list in python? For example I want numbers starting from 3000 to 3100 that are stored in a list and are also in string format.
Something like this ['3000', '3001', '3002', ......., '3100']
How can I generate a sequence of string numbers in a list in python? For example I want numbers starting from 3000 to 3100 that are stored in a list and are also in string format.
Something like this ['3000', '3001', '3002', ......., '3100']
Use the range
function, then combine with a map(str,)
# list of int
values = list(range(3000, 3101))
print(values) # [3000, 3001, 3002, 3003, 3004 ... 3100]
# list of string representation of int
values = list(map(str, range(3000, 3101)))
print(values) # ['3000', '3001', '3002', '3003',, ... '3100']
first, you can generate a list from numbers, and then you can convert the type of the elements to a string.
mylist=list(range(3000,3101))
convertlist = list()
for x in mylist:
convertlist.append(str(x))
print(convertlist)
print(type(convertlist[0]))