8(iii)
Write a Python program that performs the following operations on a string:
- (a)Define a string with the value "Machine Learning".
- (b)Convert the string to lowercase and print it.
- (c)Replace the word "Machine" with "Deep".
- (d)Check if the string ends with "Learning" and print the result (True/False).
- (e)Count and print the number of occurrences of the letter "n".
Show SolutionHide Solution↓
s = "Machine Learning"
lower_s = s.lower()
print("Lowercase string:", lower_s)
replaced_s = s.replace("Machine", "Deep")
print("After replacement:", replaced_s)
ends = s.endswith("Learning")
print("Ends with 'Learning':", ends)
count_n = s.count('n')
print("Number of occurrences of 'n':", count_n)
Lowercase string: machine learning
After replacement: Deep Learning
Ends with 'Learning': True
Number of occurrences of 'n': 3