An example that uses most of the list methods: 

>>> fruits =['orange','apple','pear','banana','kiwi ','apple','banana'] >>> fruits.count( 'apple') 2 >>> fruits.count( 'tangerine') 0 >>> fruits.index('banana') 3 >>> fruits.index('banana',4) # Find next banana starting a position 4 6 >>> fruits.reverse() >>> fruits ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange'] >>> fruits.append( 'grape') >>> fruits ['banana', 'apple', 'kiwi', 'banana', 'pear', 'apple', 'orange', >>> fruits.sort() >>> fruits ['apple', 'apple', 'banana', 'banana', 'grape', 'kiwi', 'orange', >>> fruits.pop() 'pear' 

You might have noticed that methods like insert , remove or sort that only modify the list have no return value printed – they return the default$_{None}$ . 1 This is a design principle for all mutable data structures in Python. 

Another thing you might notice is that not all data can be sorted or compared. For instance,$_{[None, 'hello',}$ 10] doesn’t sort because integers can’t be compared to strings and None can’t be compared to other types. Also, there are some types that don’t have a defined ordering relation. For example,$_{3+4j < 5+7j}$ isn’t a valid comparison. 

## 5.1.1 Using Lists as Stacks 

The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved (“last-in, first-out”). To add an item to the top of the stack, use$_{append()}$ . To retrieve an item from the top of the stack, use$_{pop()}$ without an explicit index. For example: 

>>> stack =[3,4,5] >>> stack.append( 6) >>> stack.append( 7) >>> stack [3, 4, 5, 6, 7] >>> stack.pop() 7 >>> stack [3, 4, 5, 6] >>> stack.pop() 6 >>> stack.pop() 5 >>> stack [3, 4] 

1 Other languages may return the mutated object, which allows method chaining, such as 

