Source: Datacamp
Datacamp DAILY Practice + daily collection.
Methods
String Methods
List Methods
Lack of a
Methods
You can think of methods as functions this "belong to" Python objects.
String Methods
# string to experiment With:room poolhouse " # use Upper () on room:room_up room_up = Room.upper ( # Print out and rosom_up Span style= "color: #0000ff;" >print print (ROOM_UP) # Print out the number of O ' s in The print (Room.count ( " o ))
Poolhouse
Poolhouse
3
List Methods
# Create list areasareas = [11.25, 18.0, 20.0, 10.75, 9.50]# Print out the index of the Elem ENT 20.0print(Areas.index (20.0))# print out how often 14.5 appears in areas Print (Areas.count (14.5))
# Create list areasareas = [11.25, 18.0, 20.0, 10.75, 9.50]# use append twice to add Poolhou SE and garage sizeareas.append (24.5) areas.append (15.45)# Print out areas Print (Areas) # Reverse The orders of the elements in areas Areas.reverse () # Print out Areas Print (areas)
Python Notes #04 # Methods