0% found this document useful (0 votes)
3 views

Python Lab Experiments V

The document outlines exercise programs focused on string operations in Python. It includes scripts for various string manipulations, checking if a string is a palindrome, and counting characters, vowels, and spaces in a given text. Solutions for each exercise are provided as code examples.

Uploaded by

chandraninandy9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Lab Experiments V

The document outlines exercise programs focused on string operations in Python. It includes scripts for various string manipulations, checking if a string is a palindrome, and counting characters, vowels, and spaces in a given text. Solutions for each exercise are provided as code examples.

Uploaded by

chandraninandy9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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(' '))

You might also like