1.
Python program for traversal with for loop
fruit = input("Enter a fruit name:")
for char in fruit:
print(char, end=' ')
2. Python program to create, concatenate and print a string and accessing sub-
string from a given string.
s1=input("Enter first String : ");
s2=input("Enter second String : ");
print("First string is : ",s1);
print("Second string is : ",s2);
print("concatenations of two strings :",s1+s2);
print("Substring of given string :",s1[1:4]);
3. Python program for String Slicing
text = "Hello World"
b = text[1:4]
print(b)
print(text[2:])
print(text[:2])
start = 1
end = 4
print(text[start:end])
4. Python program for mutable String
greeting = 'Hello, world!'
new_greeting = 'J' + greeting[1:]
print(new_greeting)
5. Python program for searching the character position in a string
def find(word, letter):
index = 0
while index < len(word):
if word[index] == letter:
return index
index = index + 1
return -1
word = input("Enter a word:")
search=input("Enter a letter to search:")
c=find(word, search)
if c==-1:
print("Letter is not found in search")
else:
print("The index of search letter",search, "is in",c, "position")
6. Python program for search a String and count
word = input("Enter a word:")
search=input("Enter a letter to count:")
count = 0
for letter in word:
if letter == search:
count = count + 1
else:
print("Searching letter is not in the word")
break
print(count)