String Programs

Python programs for practicing string manipulation, searching, transformation, and validation.

25 program solutions

Back to Topics

Program Solutions

1

Reverse a String

Reverse a string entered by the user.

Beginner
View Solution
2

Check Palindrome String

Check whether a given string is a palindrome (ignoring case and spaces).

Beginner
View Solution
3

Count Vowels in String

Count the number of vowels in a given string.

Beginner
View Solution
4

Count Consonants in String

Count the number of consonants (alphabetic non-vowels) in a string.

Beginner
View Solution
5

Count Digits in String

Count how many digit characters appear in a string.

Beginner
View Solution
6

Remove Special Characters

Remove all non-alphanumeric characters from a string.

Beginner
View Solution
7

Remove Whitespace

Remove all whitespace characters from a string.

Beginner
View Solution
8

Find Substring

Check if a substring exists within a string and find its index.

Beginner
View Solution
9

Replace Substring

Replace all occurrences of a substring with another substring.

Beginner
View Solution
10

Character Frequency

Count the frequency of each character in a string.

Beginner
View Solution
11

Capitalize First Letter of Each Word

Capitalize the first letter of each word in a sentence.

Beginner
View Solution
12

Convert String to Title Case

Another example of converting to title case using string methods.

Beginner
View Solution
13

Sort String Characters

Sort the characters of a string in ascending order.

Beginner
View Solution
14

Find Longest Word

Find the longest word in a sentence.

Beginner
View Solution
15

Find Shortest Word

Find the shortest word in a sentence.

Beginner
View Solution
16

String Compression

Implement a simple run-length encoding (RLE) compression for strings.

Intermediate
View Solution
17

String Rotation

Check whether one string is a rotation of another.

Intermediate
View Solution
18

Anagram Check

Check whether two strings are anagrams of each other.

Beginner
View Solution
19

Split and Join Strings

Split a sentence into words and join them with a given delimiter.

Beginner
View Solution
20

Count Words in String

Count the number of words in a sentence.

Beginner
View Solution
21

Extract Numbers from String

Extract all integer numbers from a mixed string.

Intermediate
View Solution
22

Validate Email Using Regex

Validate email format specifically through regex on a string.

Intermediate
View Solution
23

Validate Phone Number Using Regex

Validate a simple phone number format using regular expressions.

Intermediate
View Solution
24

Check Pangram

Check whether a sentence is a pangram (contains every letter of the alphabet at least once).

Intermediate
View Solution
25

Convert snake_case to camelCase

Convert a snake_case string to camelCase.

Intermediate
View Solution