String Methods
Strings come with a bunch of methods. Follow the instructions closely to discover some of them. If you want to discover them in more detail, you can always type help(str)
in the IPython Shell.
A string place
has already been created for you to experiment with.
This exercise is part of the course
Introduction to Python
Exercise instructions
- Use the
.upper()
method onplace
and store the result inplace_up
. Use the syntax for calling methods that you learned in the previous video. - Print out
place
andplace_up
. Did both change? - Print out the number of o's on the variable
place
by calling.count()
onplace
and passing the letter'o'
as an input to the method. We're talking about the variableplace
, not the word"place"
!
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# string to experiment with: place
place = "poolhouse"
# Use upper() on place
place_up =
# Print out place and place_up
# Print out the number of o's in place