"""
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])
# Python хэл дээрх мөрийг давтахын тулд "for...in" тэмдэглэгээг ашиглана.
str = "hello"
for c in str:
print(c)
# h
# e
# l
# l
# o
# Iterating through a string
count = 0
for letter in 'Hello World':
if(letter == 'l'):
count += 1
print(count,'letters found')
word = "test"
for letter in word:
print(letter)
mystring = "Hello python";
for ch in mystring:
print("Index of Element :", mystring.index(ch) , " - Element of string:",ch)
"""
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)