list indices must be integers or slices, not tuple
阿新 • • 發佈:2019-02-18
以下兩種情況都會出現此錯誤:
points = [ [1, 2], [0, 4], [2, 0][12,1] ]list的維數必須一致:正確寫法:
points = [ [1, 2], [0, 4], [2, 0] ]這個也會報錯:
stations = ['Schagen', 'Heerhugowaard', 'Alkmaar', 'Castricum', 'Zaandam', 'Amsterdam', 'Sloterdijk', 'Amsterdam Centraal', 'Amsterdam Amstel', 'Utrecht Centraal', '’s-Hertogenbosch'這個是因為讀取的是時候維數錯誤:, 'Eindhoven', 'Weert', 'Roermond', 'Sittard', 'Maastricht'] IndEind = stations.index("Heerhugowaard") IndBegin = stations.index('Sloterdijk') intBegin = int(IndBegin) intEind = int(IndEind) print('stations[0]: ', stations[intBegin, intEind])
正確寫法:
print('stations[0]: ', stations[intBegin:intEind])