我正在學習有關在Python遞歸和我有這樣的代碼:Python的遞歸和列表
def search(l,key):
"""
locates key in list l. if present, returns location as an index;
else returns False.
PRE: l is a list.
POST: l is unchanged; returns i such that l[i] == key; False otherwise.
"""
if l: # checks if list exists
if l[0] == key: # base case - first index is key
return True
s = search(l[1:], key) # recursion
if s is not False:
return s
return False # returns false if key not found
有人能向我解釋,行
s = search(l[1:], key)
做究竟是什麼? [1:]對列表做了什麼?
[here](http://stackoverflow.com/questions/509211/pythons-slice-notation) –
humm,代碼似乎並沒有'返回我這樣l [i] == key' – laike9m