38 lines
856 B
Python
38 lines
856 B
Python
|
|
# https://www.w3schools.com/python/python_ref_list.asp
|
|
# https://www.quackit.com/python/reference/python_3_list_methods.cfm
|
|
|
|
programMessage = '''
|
|
The index() method locates the first element in a list.
|
|
|
|
'''
|
|
|
|
print(programMessage)
|
|
|
|
|
|
basicList = [1, 34, 99, 87, 14, 1, 34, 1,87 ]
|
|
print(f"Example list {basicList}")
|
|
|
|
myValue = 1
|
|
index = basicList.index(myValue)
|
|
print(f"The location of '{myValue}' item is at position {index}")
|
|
|
|
|
|
|
|
myValue = 1
|
|
index = basicList.index(myValue,index+1)
|
|
print(f"The next location of '{myValue}' item is at position {index}")
|
|
|
|
|
|
myValue = 1
|
|
index = basicList.index(myValue,index+1)
|
|
print(f"The next location of '{myValue}' item is at position {index}")
|
|
|
|
|
|
print("This last search generates an error.")
|
|
|
|
myValue = 1
|
|
index = basicList.index(myValue,index+1)
|
|
print(f"The next location of '{myValue}' item is at position {index}")
|
|
|
|
|