Traversing a String
Traversing a string using for loop
In the above code, the loop starts from the first character of the string str1 and automatically ends when the last character is accessed.
Traversing a string using while loop
Here the while loop runs till the condition index < len(str) is True , where index varies from 0 to len(str1) -1.