8(iii)
Write a Python program that does the following using string built-in functions:
stg = " Welcome to My Python Project "
- (a)Convert entire string to lowercase.
- (b)Replace "my" with "your".
- (c)Find the length of the new string.
- (d)Check if the string ends with 'T'.
- (e)Print the characters from index 3 to 6 in reverse order.
Show SolutionHide Solution↓
stg = " Welcome to My Python Project "
stg = stg.lower()
print("Lowercase string:", stg)
stg = stg.replace("my", "your")
print("After replacement:", stg)
length = len(stg)
print("Length of the new string:", length)
ends = stg.endswith('T')
print("Ends with 'T':", ends)
reversed_chars = stg[3:7][::-1]
print("Characters from index 3 to 6 in reverse order:", reversed_chars)
Lowercase string: welcome to my python project
After replacement: welcome to your python project
Length of the new string: 32
Ends with 'T': False
Characters from index 3 to 6 in reverse order: mocl