Program 1
String basics
Length, upper, lower, slicing.
python
s = "Python Programming"
print(len(s))
print(s.upper())
print(s.lower())
print(s[0:6])
print(s[::-1]) # reverseTopic 05 of 17
Work with text: slicing, formatting, and the most useful string methods.
Program 1
Length, upper, lower, slicing.
s = "Python Programming"
print(len(s))
print(s.upper())
print(s.lower())
print(s[0:6])
print(s[::-1]) # reverseProgram 2
Count vowels in a sentence.
text = "Beautiful is better than ugly"
count = sum(1 for ch in text.lower() if ch in "aeiou")
print("Vowels:", count)Program 1
Compare a string to its reverse.
def is_palindrome(s: str) -> bool:
s = s.lower().replace(" ", "")
return s == s[::-1]
print(is_palindrome("Race car"))
print(is_palindrome("Hello"))Program 1
Count occurrences of each word.
from collections import Counter
text = "the quick brown fox jumps over the lazy dog the fox"
freq = Counter(text.split())
print(freq.most_common(3))Program 2
Two words are anagrams if sorted letters match.
def is_anagram(a, b):
return sorted(a.lower()) == sorted(b.lower())
print(is_anagram("listen", "silent"))
print(is_anagram("hello", "world"))