Learn about List:
"" "More on Lists?
Using Lists as Stacks.
"""
Fruits = [' orange ', ' apple ', ' pear ', ' banana ', ' kiwi ', ' apple ', ' banana ']
#Return the number of times X appears in the list
Print (Fruits.count (' apple '))
Print (Fruits.count (' Tangerine '))
#Return zero-based index in the list of the first item whose value is X.
#list. Index (x[, start[, end]])
Print (Fruits.index (' Kiwi ', 4))
#Reverse The elements of the list in place.
Print ("Before reversing---------------------------------")
Print (fruits)
Fruits.reverse ()
Print ("After reversing---------------------------------")
Print (fruits)
#Add an item to the end of the list
Print ("Before appendding---------------------------------")
Print (fruits)
Fruits.append (' Grape ')
Print ("After appendding---------------------------------")
Print (fruits)
#sort (Key=none, Reverse=false)
Fruits.sort ()
Print ("After sorting---------------------------------")
Print (fruits)
#Remove the item at the given position in the list, and return it. If No index is specified, A.pop () removes and returns
# The last item in the list.
Fruits.pop ()
Print ("After poping---------------------------------")
Print (fruits)
If ' Apple ' in fruits:
Print ("in range")
Printing results:
D:\Python3.6.1\python.exe f:/python_workspace/tutorial/lists.py
2
0
4
Before reversing---------------------------------
[' Orange ', ' apple ', ' pear ', ' banana ', ' kiwi ', ' apple ', ' banana ']
After reversing---------------------------------
[' Banana ', ' apple ', ' kiwi ', ' banana ', ' pear ', ' apple ', ' orange ']
Before Appendding---------------------------------
[' Banana ', ' apple ', ' kiwi ', ' banana ', ' pear ', ' apple ', ' orange ']
After Appendding---------------------------------
[' Banana ', ' apple ', ' kiwi ', ' banana ', ' pear ', ' apple ', ' orange ', ' grape ']
After sorting---------------------------------
[' Apple ', ' apple ', ' banana ', ' banana ', ' grape ', ' kiwi ', ' orange ', ' pear ']
After Poping---------------------------------
[' Apple ', ' apple ', ' banana ', ' banana ', ' grape ', ' kiwi ', ' orange ']
In range
Basic Python Learning (iii) four