String Manipulation
String Manipulation
Manipulation
Practical 1
Q) Write a program to count the
number of times a character
occurs in the given string.
# Get user input
user_string = input("Enter a
string: ")
user_character = input("Enter the
character to count: ")
Practical 2
Q) Write a program which
replaces all vowels in the string
with '*'.
# Get user input
user_string = input("Enter a
string: ")
Result
Enter a string: thermodynamics
Modified string: th*rm*dyn*m*cs
Practical 3
Q) Write a program which reverses
a string and stores the reversed
string in a new string.
# Get user input
user_string = input("Enter a
string: ")
Result
Enter a string: Knowledge
Reversed string: egdelwonK
Practical 4
Q) Write a program that prompts
for a phone number of 10 digits
and two dashes, with dashes after
the area code and the next three
numbers.