List Methods
Strings are not the only Python types that have methods associated with them. Lists, floats, integers and booleans are also types that come packaged with a bunch of useful methods. In this exercise, you'll be experimenting with:
.index()
, to get the index of the first element of a list that matches its input and.count()
, to get the number of times an element appears in a list.
You'll be working on the list with the area of different parts of a house: areas
.
This exercise is part of the course
Introduction to Python
Exercise instructions
- Use the
.index()
method to get the index of the element inareas
that is equal to20.0
. Print out this index. - Call
.count()
onareas
to find out how many times9.50
appears in the list. Again, simply print out this number.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create list areas
areas = [11.25, 18.0, 20.0, 10.75, 9.50]
# Print out the index of the element 20.0
# Print out how often 9.50 appears in areas