# File: Erin/stringfunctions.py # Write each letter of a string on a different line # Count the number of times letter is in a string # Delete all the occurrences of a character in a string # Modify a string. Put instead of an a, an X # Insert a Z in position 3 # B # o # u # d # r # e # a # u # The number of occurrences of u is: 2 # Delete letter u: Bodrea # Replace a with X: BoudreXu # Inserts a Z in the third position: BouZdreau s = "Boudreau" # s global variable n = len(s) # length of the string for i in range(n): # print a letter on each line print(s[i]) for c in s: #same as above print(c) print("The number of occurences of u is: ", s.find('u')) print("Delete letter u: ", s.replace('u', '')) # deletes ALL occurrences print("Replace a with X: ", s.replace('a', 'X')) def myinsert(original, new, pos): # defines a function insert return original[:pos] + new + original[pos:] print("Inserts a Z in the third position: ", myinsert(s, 'Z', 3));