Python String Exercises
Let’s check out some exercises that will help you understand Python strings better.
Assign the string below to the variable in the exercise.
"It's always darkest before dawn."
By using first, second and last characters of the string, create a new string.
Replace the (.) with (!)
Reassign str so that, all its characters are lowercase.
Now make everything uppercase.
Make the string so that everything is properly and first letter is capital with one function.
Does the string start with an A?
Assign a boolean answer to the ans_1 variable.
Does it end with a fullstop (.) ?
Using .index() method, identify the index of character: (v).
Using .find() method, identify the index of character: (m).
Try to see what results you get looking for character: (X). First with .find() method and then with .index() method.
Which character occur more often in the string? "a" or "o" ? Print both counts inside the print function.
Print the types of two given variables with the print function.
What is the length of the given string?