String programs · Python Programs

String programs build skill with indexing, slicing, loops and dictionaries. Each page states the problem, solves it in more than one way, shows the output and explains why the solution works.

All 5

Python Program to Check Palindrome (String and Number)
A palindrome reads the same forwards and backwards. In Python, clean the text with `lower()` and compare it to its reverse: `s ==…
Python Program to Count Vowels in a String
To count vowels in Python, loop over the lowercase string and count the characters found in `"aeiou"`: `sum(1 for ch in text.lowe…
Python Anagram Program: Check if Two Strings Are Anagrams
Two strings are anagrams if they contain the same letters the same number of times. In Python, compare `sorted(a) == sorted(b)` a…
Python Word Count Program: Count Words in a String
To count words in Python, split the string on whitespace and take the length: `len(text.split())`.
Python Program to Count Character Frequency in a String
To count character frequency in Python, loop over the string and keep a dictionary of counts: `freq[ch] = freq.get(ch, 0) + 1`, o…

Explore more

Python ReferencePython ComparisonsPython How-To GuidesPython Cheat SheetsPython glossaryPython tutorial