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