2014-06-20 30 views

回答

0

正指數從0len(seq) - 1

負指數將從-1-len(seq)

+0

我的意思是功能,如:在 X [N,M] –

1

如果指定的索引不存在,Python將拋出IndexError。簡單地做:

def contains_index(l, index): 
    try: 
     temp = l[index] 
     return True 
    except IndexError: 
     return False 
相關問題