String Programs
Python programs for practicing string manipulation, searching, transformation, and validation.
25 program solutions
Program Solutions
Reverse a String
Reverse a string entered by the user.
Check Palindrome String
Check whether a given string is a palindrome (ignoring case and spaces).
Count Vowels in String
Count the number of vowels in a given string.
Count Consonants in String
Count the number of consonants (alphabetic non-vowels) in a string.
Count Digits in String
Count how many digit characters appear in a string.
Remove Special Characters
Remove all non-alphanumeric characters from a string.
Remove Whitespace
Remove all whitespace characters from a string.
Find Substring
Check if a substring exists within a string and find its index.
Replace Substring
Replace all occurrences of a substring with another substring.
Character Frequency
Count the frequency of each character in a string.
Capitalize First Letter of Each Word
Capitalize the first letter of each word in a sentence.
Convert String to Title Case
Another example of converting to title case using string methods.
Sort String Characters
Sort the characters of a string in ascending order.
Find Longest Word
Find the longest word in a sentence.
Find Shortest Word
Find the shortest word in a sentence.
String Compression
Implement a simple run-length encoding (RLE) compression for strings.
String Rotation
Check whether one string is a rotation of another.
Anagram Check
Check whether two strings are anagrams of each other.
Split and Join Strings
Split a sentence into words and join them with a given delimiter.
Count Words in String
Count the number of words in a sentence.
Extract Numbers from String
Extract all integer numbers from a mixed string.
Validate Email Using Regex
Validate email format specifically through regex on a string.
Validate Phone Number Using Regex
Validate a simple phone number format using regular expressions.
Check Pangram
Check whether a sentence is a pangram (contains every letter of the alphabet at least once).
Convert snake_case to camelCase
Convert a snake_case string to camelCase.
Topic Strategy: String Programs
This topic is best practiced through repetition with variation. Solve each program, then modify constraints and test alternate approaches so you understand why one solution performs better than another.
During interviews, explain the approach before coding: input assumptions, core logic, complexity, and edge cases. Clear reasoning often matters as much as final code correctness.
Once comfortable, time-box each question and target clean, readable code with meaningful variable names and a quick dry run explanation.