list.index(obj)
obj -- 這是要查詢的物件。
#!/usr/bin/python3 list1 = ['physics', 'chemistry', 'maths'] print ('Index of chemistry', list1.index('chemistry')) print ('Index of C#', list1.index('C#'))
Traceback (most recent call last): File "test.py", line 3, in print ('Index of C#', list1.index('C#')) ValueError: 'C#' is not in list