Python String Program
Python String Program
Python String Program
string=input("Enter string:")
string=string.replace('a','$')
string=string.replace('A','$')
print("Modified string:")
print(string)
Python Program to Take in a String and Replace Every Blank Space with Hyphen
string=input("Enter string:")
string=string.replace(' ','-')
print("Modified string:")
print(string)
Python Program to Calculate the Number of Words and the Number of Characters Present in a String
string=input("Enter string:")
char=0
word=1
for i in string:
char=char+1
if(i==' '):
word=word+1
print("Number of words in the string:")
print(word)
print("Number of characters in the string:")
print(char)
Python Program to Count the Occurrences of Each Word in a Given String Sentence
string=input("Enter string:")
word=input("Enter word:")
a=[]
count=0
a=string.split(" ")
for i in range(0,len(a)):
if(word==a[i]):
count=count+1
print("Count of the word is:")
print(count)
string=input("Enter string:")
sub_str=input("Enter word:")
if(string.find(sub_str)==-1):
print("Substring not found in string!")
else:
print("Substring in string!")