开发者

Python - How to clear a integer from a list completely?

# 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(ti开发者_如何学运维me)
[[], 27, 32, 36.5, 38.5, 40.5, 41.5, 42, 43.5, 45.5, 47.5, 52.5]

I'm just following what the tutorial has taught me so far:

http://docs.python.org/py3k/tutorial/introduction.html#lists


You want del for this.

del time[0]


For completeness:

time.remove(15)

But in this case I'd use:

del time[0]


Actually, if you want to do as the example suggests, you'd be doing

time[0:1] = []


There are literally countless ways to do this.

I prefer time = time[1:]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜