V. Exercise programs on Strings.
a) Implement Python Script to perform various opera ons on string using string libraries.
b) Implement Python Script to check given string is palindrome or not.
c) Implement python script to accept line of text and find the number of characters, number of
vowels and number of blank spaces in it
Try yourself first
Solu ons Below
a) String Opera ons
s = "Hello, World!"
print("Length:", len(s))
print("Uppercase:", s.upper())
print("Lowercase:", s.lower())
print("Count 'l':", s.count('l'))
print("Split:", s.split())
print("Joined:", ' '.join(s.split()))
b) Palindrome Check
s = input("Enter a string: ").replace(" ", "").lower()
print("Palindrome" if s == s[::-1] else "Not a palindrome")
c) Count Characters, Vowels, and Spaces
text = input("Enter text: ")
vowels = "aeiouAEIOU"
print("Characters:", len(text))
print("Vowels:", sum(1 for c in text if c in vowels))
print("Spaces:", text.count(' '))