Phase 5 - Category 4: String Transformation
Transform strings - replace, remove, insert operations.
10 programs · open one, then the next
Start with Replace Character- 01Replace CharacterIntermediateReplace all occurrences of a character.Open example →py# Take string input s = input("Enter a string: ") old_char = input("Enter character to replace: ") new_char = input("Enter new character: ")
- 02Remove CharacterIntermediateRemove all occurrences of a character.Open example →py# Take string input s = input("Enter a string: ") char_to_remove = input("Enter character to remove: ")
- 03Insert Character at PositionIntermediateInsert character at given position.Open example →py# Take string input s = input("Enter a string: ") char = input("Enter character to insert: ") pos = int(input("Enter position: "))
- 04Remove First CharacterBeginnerRemove first character from string.Open example →py# Take string input s = input("Enter a string: ") # Remove first character
- 05Remove Last CharacterBeginnerRemove last character from string.Open example →py# Take string input s = input("Enter a string: ") # Remove last character
- 06Swap First and Last CharacterIntermediateSwap first and last character.Open example →py# Take string input s = input("Enter a string: ") # Swap first and last
- 07Duplicate String N TimesBeginnerPrint string n times.Open example →py# Take string input s = input("Enter a string: ") n = int(input("Enter number of times: "))
- 08Add Characters Between Each CharacterIntermediateAdd a character between each character.Open example →py# Take string input s = input("Enter a string: ") char = input("Enter character to add: ")
- 09Remove All Occurrences of SubstringIntermediateRemove all occurrences of a substring.Open example →py# Take string input s = input("Enter a string: ") substring = input("Enter substring to remove: ")
- 10Reverse Each WordIntermediateReverse each word in string.Open example →py# Take string input s = input("Enter a string: ") # Reverse each word