Python pt.5 Lists - mattl1598/Project-Mochachino GitHub Wiki

Python pt.5 - Lists

List Initialisation

One Dimensional Lists:

list = []

If Statements

You can check if a number exists in a LIST using the IF statement in the following manner:

myList = [1,2,3,4,5]

if 3 in myList:
    print("3 is present")

List Methods

Method Description
.append(value) adds elements to end of the list
.count("x") counts the number of occurrences of x
index("x") returns the index of “x” in the list
.insert("y","x") inserts “x” at location “y”
.pop() returns last element then removes it
remove("x") finds and removes first ‘x’ from list
.sort() sorts the list in ascending order