Added code for lecture 2026-11-10
This commit is contained in:
parent
5b630435ae
commit
07b9e54bf0
52 changed files with 1248 additions and 1 deletions
38
lecture20261110/listmethods/list07MethodIndex.py
Normal file
38
lecture20261110/listmethods/list07MethodIndex.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
# 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}")
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue