I am relatively inexperienced and come from c#. I am attempting to iterate through a string and individually print out each letter using a for loop.
In c# this would (if I remember correctly) be written like so:
string x = test;
foreach(i in x)
{
print(x[i]);
}
But in python, when I type
x = "test"
for i in x:
print(x[i])
The python shell tells me that i must be an integer.
I am actually pretty sure that my syntax is incorrect in my c# example, but to get to the question:
How would i properly iterate through a string using a for, or foreach loop in Python?
I have been searching the web and am somehow coming up empty handed. Sorry if this is a foolish inquiry.
for i in xgrabs each character inx. Indexing withx[i]won't work because you're using a character for the index. Change it tofor i in range(len(x))to get it working correctly.