Use string formatting and list comprehension:

>>> lst = range(11)
>>> ["{:02d}".format(x) for x in lst]
['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10']

or format:

>>> [format(x, '02d') for x in lst]
['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10']
Answer from Ashwini Chaudhary on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python-convert-string-ranges-to-list
Python | Convert String ranges to list | GeeksforGeeks
May 16, 2023 - ... # Python3 code to demonstrate working of # Convert String ranges to list # Using sum() + list comprehension + enumerate() + split() # initializing string test_str = "1, 4-6, 8-10, 11" # printing original string print("The ...
Discussions

loops - Generating a range of numbers as strings Python - Stack Overflow
I need to loop over a number of files with structured files names. They are of the form 'Mar00.sav', 'Sep00.sav', 'Mar01.sav' At the moment I do this; Years = ['01', '02', '03', '04', '05', '06'... More on stackoverflow.com
🌐 stackoverflow.com
How to convert numeric string ranges to a list in Python - Stack Overflow
I would like to be able to convert a string such as "1,2,5-7,10" to a python list such as [1,2,5,6,7,10]. I looked around and found this, but I was wondering if there is a clean and simple way to d... More on stackoverflow.com
🌐 stackoverflow.com
python - Create a list with string + range - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I want to create a list looking like this ['Unnamed: 16', 'Unnamed: 17', 'Unnamed:18'] for a range (16,60). How can I proceed? I don't know if my question is clear but it's like doing list(range(16, 60) but with a string ... More on stackoverflow.com
🌐 stackoverflow.com
python - How to transfer range() output into string - Stack Overflow
How to create a list of string using range() built-in function in python? More on stackoverflow.com
🌐 stackoverflow.com
🌐
EyeHunts
tutorial.eyehunts.com β€Ί home β€Ί python range to the list of strings | example code
Python range to the list of strings | Example code - EyeHunts
August 27, 2021 - They are of the form β€˜Mar00.sav’, β€˜Sep00.sav’, β€˜Mar01.sav’ Β· Python simple example code. There is a perfect solution to it -zfill method. Generator for N numbers and fill its string representation with zeros. list1 = [] for i in range(1, 7): list1.append(str(i).zfill(2)) print(list1) Output: lst = range(11) print(["{:02d}".format(x) for x in lst]) Output: [’00’, ’01’, ’02’, ’03’, ’04’, ’05’, ’06’, ’07’, ’08’, ’09’, ’10’] or format: lst = range(11) print([format(x, '02d') for x in lst]) Output: [’00’, ’01’, ’02’, ’03’, ’04’, ’05’, ’06’, ’07’, ’08’, ’09’, ’10’] sr = [] for r in range(11): sr.append('i' % r) print(sr) Do comment if you have any doubts and suggestions on this Python list topic.
🌐
Python Examples
pythonexamples.org β€Ί python-convert-numeric-string-range-to-a-list
How to Convert Numeric String Range to a List in Python?
To convert numeric string range like '4-9' to a list like [4, 5, 6, 7, 8, 9] in Python: split the string using hyphen as delimiter, convert the splits to integers, create a range using these integers, and then convert the range to a list.
🌐
YouTube
youtube.com β€Ί watch
python range to string list - YouTube
Download this code from https://codegive.com In Python, the range function is commonly used to generate a sequence of numbers. While range itself returns a r...
Published Β  February 2, 2024
🌐
Stanford CS
cs.stanford.edu β€Ί people β€Ί nick β€Ί py β€Ί python-range.html
Python range() Function
The difference is the "step" amount ... before, the stop number itself is always omitted. >>> list(range(0, 10, 2)) [0, 2, 4, 6, 8] >>> list(range(0, 10, 6)) [0, 6] >>> list(range(200, 800, 100)) [200, 300, 400, 500, 600, 700]...
🌐
Spark By {Examples}
sparkbyexamples.com β€Ί home β€Ί python β€Ί convert range to list in python
Convert Range to List in Python - Spark By {Examples}
May 31, 2024 - How to convert the range of values to a list in Python? There are multiple ways to convert the range to a list in Python for example you can use the
Find elsewhere
🌐
TutorialKart
tutorialkart.com β€Ί python β€Ί python-range β€Ί python-range-to-list
Convert Python Range to List - Examples
November 30, 2020 - To convert a Python Range to Python List, use list() constructor, with range object passed as argument. list() constructor returns a list generated using the range. Or you can use a for loop to append each item of range to list.
🌐
University at Buffalo
math.buffalo.edu β€Ί ~badzioch β€Ί MTH337 β€Ί PT β€Ί PT-lists.html
Lists, ranges and β€œfor” loops β€” MTH 337
The iteration variable letter gets bound to each string character in turn: for letter in 'hello': if letter != 'l': print(letter) ... As the examples above illustrate in many situations we may need to iterate a for loop over a sequence of consecutive integers. It would be inconvenient having to manually type a list of integers to code such iteration. Instead we can use the range function that generates integers in a given range.
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 68491454 β€Ί using-range-function-in-python
loops - Using range function in Python - Stack Overflow
Every string in Python ist iterable, so don't use another generator like range. But if your string is "a b c d e f g", every second element is a space " ". Here you'd use for i in "a b c d e f g".split(" ") ;) (and concatenate in a new variable as Barmar said) ... Your example doesn't work, because i = i.upper() does not reassign the uppercase letter back to the original string.
🌐
Python Examples
pythonexamples.org β€Ί python-convert-range-into-a-list
Convert Range into a List
In the following example, we take a range object starting at 4, and progressing upto 10 (excluding 10), and convert this range object into a list. # Take a range myrange = range(4, 10) # Convert range object into a list mylist = list(myrange) print(mylist) ... In the following example, we take ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-construct-n-range-equilength-string-list
Python | Construct N Range Equilength String list - GeeksforGeeks
May 17, 2023 - Number of elements required : 6 K Length range strings list : ['000', '001', '002', '003', '004', '005'] Time Complexity: O(n), where n is the length of the list test_list Auxiliary Space: O(n) additional space of size n is created where n is the number of elements in the res list Β· Method #3: Using List Comprehension + format method ... # Python3 code to demonstrate working of # Construct N Range Equilength String list # using format method # initialize N N = 6 # printing N print("Number of elements required : " + str(N)) # initialize K K = 3 res = ['{:0{}}'.format(i, K) for i in range(N)] # printing result print("K Length range strings list : " + str(res)) #this code is contributed by edula vinay kumar reddy
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί not really understanding when to use for i in string vs for i in range(len(string))
r/learnpython on Reddit: Not really understanding when to use for I in string vs for I in range(len(string))
September 27, 2020 -

Just looking for clarification for this very simple thing. Please correct me if I’m wrong but from what I understand, in for i in string, it takes each element in the string over the entire length. For i in range(len(string)) it indexes the elements and looks at the elements at each index so at position 0, string =β€˜x’ and at 1 string= β€˜d’ ect.

If this is correct, I’m afraid I still don’t see the difference by way of when to use each or what purpose they serve.

🌐
GeeksforGeeks
geeksforgeeks.org β€Ί range-to-a-list-in-python
range() to a list in Python - GeeksforGeeks
April 17, 2025 - List comprehension provides another efficient and Pythonic way to convert a range object into a list. ... The comprehension iterates through each element in the range object. Each element is added to the new list, resulting in the complete conversion. The unpacking operator * can unpack the elements of a range object directly into a list.