Python | 程序从列表中删除范围内的所有元素
生活随笔
收集整理的這篇文章主要介紹了
Python | 程序从列表中删除范围内的所有元素
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Given a list and we have to remove elements in a range from the list in Python.
給定一個列表,我們必須從Python中的列表中刪除范圍內的元素。
刪除列表(開始索引,結束索引) (del list(start_index, end_index))
del() method is used to remove all elements of list in range starting from start_index to end_index.
del()方法用于刪除從start_index到end_index范圍內的list的所有元素。
Syntax:
句法:
del list(start_index, end_index)Program:
程序:
# Declaring a list list = [10, 20, 30, 40, 50]# print list print "List element:" for l in range(len(list)):print (list[l])# delete element from index 1 to 30del list[1.3] del list[1:3]# print list after deleting # element from index 1 to 3 print "List element after del[1:3]:" for l in range(len(list)):print (list[l])Output
輸出量
List element:1020304050List element after del[1:3]:104050翻譯自: https://www.includehelp.com/python/remove-all-elements-in-a-range-from-the-list.aspx
總結
以上是生活随笔為你收集整理的Python | 程序从列表中删除范围内的所有元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 颐和园成人门票多少钱
- 下一篇: 杭州看无精症最好的医院推荐