Let's say I have
myString = "ORANGE"
How can I write a for-each loop that lists each character so it looks like this
1O
2R
3A
4N
5G
6E
I am confused as I don't know how to do it without using range.
This is quite basic. 5 answers and none of them actually say this I am surprised. Never mind this should do what you asked for:
myString = "ORANGE"
a = 1
for i in myString:
print(str(a) + i)
a = a + 1
myString = "ORANGE"
l = [str(i)+j for i,j in enumerate(myString,1)]
' '.join(l)
Output:
'1O 2R 3A 4N 5G 6E'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With