2011-02-08 38 views
2
# Assign list "time" with the following time values.  
time = [15, 27, 32, 36.5, 38.5, 40.5, 41.5, 42, 43.5, 45.5, 47.5, 52.5] 
# Remove 1st value(0) from the list 
time[0] = [] 
# Show time 
time 
[[], 27, 32, 36.5, 38.5, 40.5, 41.5, 42, 43.5, 45.5, 47.5, 52.5] 
# Print time 
print(time) 
[[], 27, 32, 36.5, 38.5, 40.5, 41.5, 42, 43.5, 45.5, 47.5, 52.5] 

我只是跟随着什么教程教我至今:
http://docs.python.org/py3k/tutorial/introduction.html#listsPython - 如何完全清除列表中的整数?

回答

8

你想del这一点。

del time[0] 
0

实际上有无数的方法来做到这一点。

我喜欢time = time[1:]

+0

这也会起作用,没有想到这一点。 – Josh 2011-02-08 04:34:45

4

出于完整性:

time.remove(15) 

但在这种情况下,我会使用:

del time[0] 
1

其实,如果你想要做的例子表明,你倒是做

time[0:1] = []