6(iii)
Write a Python program that performs the following operations on a string:
- (a)Create a string with the value "Computer Applications"
- (b)Find and print the length of the string.
- (c)Count and print the occurrences of 'p' in the substring "Applications"
- (d)Find and print the position of the substring "Applications" within the string.
- (e)Check whether the string is in uppercase and print the result.
- (f)Replace the substring "Applications" with "Science" and print the new string.
Show SolutionHide Solution↓
s = "Computer Applications"
length = len(s)
print("Length of the string:", length)
count_p = "Applications".count('p')
print("Occurrences of 'p' in 'Applications':", count_p)
pos = s.find("Applications")
print("Position of 'Applications':", pos)
upper_check = s.isupper()
print("Is the string in uppercase:", upper_check)
new_s = s.replace("Applications", "Science")
print("New string:", new_s)
Length of the string: 21
Occurrences of 'p' in 'Applications': 2
Position of 'Applications': 9
Is the string in uppercase: False
New string: Computer Science