Robotics & Artificial Intelligence
Write a Python program that performs the following operations on a string:
- Define a string with the value "Machine Learning".
- Convert the string to lowercase and print it.
- Replace the word "Machine" with "Deep".
- Check if the string ends with "Learning" and print the result (True/False).
- Count and print the number of occurrences of the letter "n".
Python String Manipulation
2 Likes
Answer
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)Output
Lowercase string: machine learning
After replacement: Deep Learning
Ends with 'Learning': True
Number of occurrences of 'n': 3
Answered By
2 Likes
Related Questions
Briefly explain supervised learning.
Write a Python program that performs the following tasks on a tuple.
- Create a tuple with elements (12, 27, 30, 47, 55, 49)
- Convert tuple into list.
- Remove element 30 from the list.
- Append a new list with elements [5, 25]
- Insert element 11 at index 3.
- Print the list.
- Convert the list to a tuple.
What is Tinkercad? Give any two features of the Tinkercad workspace.
Give any three different ways to represent data to gather meaningful information.