Traversing a String

Traversing a string using for loop

How to traverse a String in Python? - Iteration in Pythoin - Concepts

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

part 2 - Traversing a String - Concepts - Chapter 8 Class 11 - Strings - Computer Science - Class 11

Here the while loop runs till the condition index < len(str) is True , where index varies from 0 to len(str1) -1.

Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.