how to iterate string in python code example
Example 1: iterating string in python
"""
Python Program:
Using range() to iterate over a string in Python
"""
string_to_iterate = "Data Science"
for char_index in range(len(string_to_iterate)):
print(string_to_iterate[char_index])
Example 2: loop through words in a string python
str = 'Hello! I am Robot. This is a Python example.'
splits = str.split()
for split in splits:
print(split)
Example 3: python iterate over string
word = "test"
for letter in word:
print(letter)
Example 4: how to loop through string in python
for i in "Hello":
print(i)
Example 5: iterate through characters in a string python
for c in "string":
Example 6: iterating string in python
"""
Python Program:
Using slice [] operator to iterate over a string partially
"""
string_to_iterate = "Python Data Science"
for char in string_to_iterate[0 : 6 : 1]:
print(char)