1. Write a Python program to calculate the length of a string.
Sample Output
Tutor Joes
Length of String = 10
2. Write a Python program to count the number of characters (character frequency) in a string.
Sample Output
tutorjoes
{'t' : 2, 'u' : 1, 'o' : 2, 'r' : 1, 'j' : 1, 'e' : 1, 's' : 1}
3. Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '@', except the first char itself.
Sample Output
Given String = tutor joes
After String = tu@or joes
4. Write a Python program to get a single string from two given strings, separated by a space and swap the first two characters of each string.
Sample Output
Before Swap = abc xyz
After Swap = xyc abz
5. Write a Python program to remove the nth index character from a nonempty string.
Sample Output
Before Remove = Tutor Joes
Remove character = t
After Remove = Tuor Joes
6. Write a Python program to change a given string to a new string where the first and last chars have been exchanged
Sample Output
Before Exchange = Python
After Exchange = nythoP
7. Write a Python program to remove the characters which have odd index values of a given string
Sample Output
String = Computer Education
Remove Odd Index Char = Cmue dcto
8. Write a Python program to count the occurrences of each word in a given sentence
Sample Output
string = To change the overall look your document. To change the look available in the gallery
{ 'To': 2, 'change': 2, 'the': 3, 'overall': 1, 'look': 2, 'your': 1, 'document.': 1, 'available': 1, 'in': 1, 'gallery': 1 }
9. Write a Python script that takes input from the user and displays that input back in upper and lower cases.
Sample Output
Enter the String = Tutor Joes
Uppercase = TUTOR JOES
Lowercase = tutor joes
10. Write a Python function to reverses a string if it's length is a multiple of 4.
Sample Output
Enter the String = Computer
If the length is a multiple of 4 = retupmoC
Enter the String = Science
If the length is not a multiple of 4 = Science
11. Write a Python function to convert a given string to all uppercase if it contains at least 2 uppercase characters in the first 4 characters.
Sample Output
Enter the String = ComPuTeR
Check if there are at least 2 uppercase letters in the first 4 characters = COMPUTER
Enter the String = Computer
Check if does not contain at least 2 uppercase letters in the first 4 characters = Computer
12. Write a Python program to sort a string lexicographically.
Sample Output
Enter the String = Tutor
['o', 'r', 'T', 't', 'u']
13. Write a Python program to remove a newline in Python.
Sample Output
String = "\nTutor \nJoes \nComputer \nEducation\n"
Before Remove NewLine(\n)
Tutor
Joes
Computer
Education
After Remove NewLine(\n) = Tutor Joes Computer Education
14. Write a Python program to check whether a string starts with specified characters.
Sample Output
Tutor Joes Computer Education
Prefix to check = Tu
Check if the input string starts with the prefix = True
15. Write a Python program to display formatted text (width=35,70) as output.
Sample Output
Python is an interpreted, object-oriented, high-level programming language
that can be used for a wide variety of applications. Python is a powerful
general-purpose programming language.
Formatted Text (Width 35) :
Python is an interpreted, object-
oriented, high-level programming
language that can be used for a
wide variety of applications.
Python is a powerful general-purpose
programming language.
Formatted Text (Width 70) :
Python is an interpreted, object-oriented, high-level programming language
that can be used for a wide variety of applications. Python is a powerful
general-purpose programming language.
16. Write a Python program to remove existing indentation from all of the lines in a given text.
Sample Output
Original text :
Python is an interpreted, object-oriented, high-level programming language
that can be used for a wide variety of applications. Python is a powerful
general-purpose programming language.
Dedented text :
Python is an interpreted, object-oriented, high-level programming language
that can be used for a wide variety of applications. Python is a powerful
general-purpose programming language.
17. Write a Python program to add a prefix text to all of the lines in a string.
Sample Output
Text :
Python is an interpreted, object-oriented, high-level programming language
that can be used for a wide variety of applications. Python is a powerful
general-purpose programming language.
Prefix to add to each line = *
Display the Result :
* Python is an interpreted, object-oriented, high-level programming language
* that can be used for a wide variety of applications. Python is a powerful
* general-purpose programming language.
18. Write a Python program to print the following floating numbers upto 2 decimal places.
Sample Output
Floating Point Number = 23.36778
Print Number with two Decimal Places = 23.36
19. Write a Python program to print the following floating numbers upto 2 decimal places with a sign
Sample Output
Floating Point Number1 = -84.99
Print Number with a sign and two decimal places = -84.99
Floating Point Number2 = 23.36778
Print Number with a sign and two decimal places = +23.37
20. Write a Python program to print the following floating numbers with no decimal places
Sample Output
Floating Point Number = 23.36778
No Decimal Places = 23
21. Write a Python program to print the following integers with zeros on the left of specified width
Sample Output
Number1 = 23
Formatted Number1(left padding, width 2) = 23
Number2 = 833
Formatted Number2(left padding, width 6) = 000833
22. Write a Python program to reverse a string.
Sample Output
String = Python Exercises
Reverse String = sesicrexE nohtyP
23. Write a Python program to reverse words in a string.
Sample Output
String = Tutor Joes Computer Educations
Reverse Words = Educations Computer Joes Tutor
24. Write a Python program to strip a set of characters from a string.
Sample Output
String = Tutor Joes Computer Education
After stripping aeiou AEIOU = T t r J s C m p t r d c t n
25. Write a Python program to convert a given string into a list of words.
Sample Output
Tutor Joes Computer Education
[ 'Tutor', 'Joes', 'Computer', 'Education' ]
26. Write a Python program to swap comma and dot in a string.
Sample Output
Before Swap Comma and Dot = 23,2000.00
After Swap Comma and Dot = 23.2000,00
27. Write a Python program to count and display the vowels of a given text.
Sample Output
Text = Tutor Joes
Vowels Character = [ 'u' , 'o' , 'o' , 'e' ]
Vowels Count = 4
28. Write a Python program to split a string on the last occurrence of the delimiter.
Sample Output
String = "T,u,t,o,r,J,o,e,s"
Delimiter = ","
['T,u,t,o,r', 'J', 'o', 'e', 's']
['T,u,t,o,r,J,o', 'e', 's']
29. Write a Python program to find the first non-repeating character in given string.
Sample Output
String = Tutor Joes
T
u
t
r
J
e
s
30. Write a Python program to find the first repeated word in a given string.
Sample Output
String = Hello world ! Hello Tutor Joes
First Repeated Word = Hello
31. Write a Python program to remove spaces from a given string.
Sample Output
String = Tutor Joes Computer Education
Remove Spaces = TutorJoesComputerEducation
32. Write a Python program to remove duplicate characters of a given string.
Sample Output
String = String and String Function
Remove Duplicate Characters in String = String adFuco
33. Write a Python program to compute sum of digits of a given string.
Sample Output
String = Hello World 2345
Sum of Digits of a Given String = 14
34. Write a Python program to remove all consecutive duplicates of a given string
Sample Output
string = AAAABBBBCCCC
Removing Consecutive Duplicates = ABC
35. Write a Python program to create a string from two given strings concatenating uncommon characters of the said strings
Sample Output
String1 = ABCPQXYZ
String2 = XYNZABMC
Concatenating Uncommon Characters = PQNM
36. Write a Python program to move all spaces to the front of a given string in single traversal.
Sample Output
String = Tutor Joes Computer Education
After Moving all Spaces to the Front = TutorJoesComputerEducation
37. Write a Python program to count Uppercase, Lowercase, special character and numeric values in a given string
Sample Output
Strings = Hell0 W0rld ! 123 * #
UpperCase = 2
LowerCase = 6
NumberCase = 5
SpecialCase = 8
38. Write a Python program to count number of non-empty substrings of a given string.
Sample Output
formula = ( ( length of the string ) * ( length of the string + 1 ) / 2 )
Input a string = Joes
Number of substrings = 10
39. Write a Python program to find smallest and largest word in a given string.
Sample Output
Strings = Tutor Joes Computer Education
Smallest word = Joes
Largest word = Education
40. Write a Python program to count number of substrings with same first and last characters of a given string.
Sample Output
Enter The String = Python
Number of substrings with the same first and last characters = 6
41. Write a Python program to find the index of a given string at which a given substring starts. If the substring is not found in the given string Not found.
Sample Output
String = Python Exercises
Substring to Find = EX
Index of the Substring = 7
42. Write a Python program to wrap a given string into a paragraph of given width.
Sample Output
Enter a String = Tutor Joes Computer Education
Enter the Width of the Paragraph = 5
Tutor
Joes
Compu
ter E
ducat
ion
43. Write a Python program to print four values decimal, octal, hexadecimal (capitalized), binary in a single line of a given integer.
Sample Output
Input an integer = 10
Decimal = 10
Octal = 12
Hexadecimal (capitalized) = A
Binary = 1010
44. Write a Python program to swap cases of a given string.
Sample Output
String = Tutor Joes Computer Education
Swap Cases = tUTOR jOES cOMPUTER eDUCATION
45. Write a Python program to delete all occurrences of a specified character in a given string.
Sample Output
String = Tutor Joes Computer Education
Character to Delete = 't'
Remove All Occurrences = Tuor Joes Compuer Educaion
46. Write a Python program find the common values that appear in two given strings.
Sample Output
String1 = UpperCase
String2 = LowerCase
Common Values = erCase
47. Write a Python program to check whether a given string contains a capital letter, a lower case letter, a number and a minimum length.
Sample Output
Enter the string = Hello123
Valid string
Enter the string = GoodEvening
String must have 1 Number.
String length should be at least 8.
Enter the string = 12345
String must have 1 Uppercase Character.
String must have 1 Lowercase Character.
String length should be at least 8.
Enter the string = Python
String must have 1 Number.
String length should be atleast 8.
48. Write a Python program to remove duplicate words from a given string.
Sample Output
String = Python Exercises Practice Solution Exercises
After Removing Duplicate = Python Exercises Practice Solution
49. Write a Python program to split a given multiline string into a list of lines.
Sample Output
String = "Tutor\nJoes\nComputer\nEducation"
['Tutor', 'Joes', 'Computer', 'Education']
multiline_string = """ Tutor
Joes
Computer
Education """
['Tutor', 'Joes', 'Computer', 'Education']
50. Write a Python program to remove punctuations from a given string.
Sample Output
String = Remove. punctuations @from a% given string?
After removing Punctuations = Remove punctuations from a given string
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions