日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 示例_带有示例的Python列表remove()方法

發(fā)布時間:2025/3/11 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 示例_带有示例的Python列表remove()方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python 示例

列出remove()方法 (List remove() Method)

remove() method is used to remove the first occurrence of the given element, the method is called with this list (the list from which we have to remove the element) and accepts the element to be removed as an argument.

remove()方法用于刪除給定元素的第一次出現(xiàn),該方法用此列表(必須從中刪除元素的列表)調(diào)用,并接受要刪除的元素作為參數(shù)。

Syntax:

句法:

list_name.remove(element)

Parameter(s):

參數(shù):

  • element – It represents the element to be removed.

    element –它表示要刪除的元素。

Return value:

返回值:

The return type of this method is <class 'NoneType'>, it returns nothing.

此方法的返回類型為<class'NoneType'> ,它什么也不返回。

Example 1:

范例1:

# Python List remove() Method with Example# declaring the list cars = ["BMW", "Porsche", "Audi", "Lexus", "Audi"]# printing the list print("cars before remove operations...") print("cars: ", cars)# removing "BMW" cars.remove("BMW") # removing "Audi" cars.remove("Audi")# printing the list print("cars after remove operations...") print("cars: ", cars)

Output

輸出量

cars before remove operations... cars: ['BMW', 'Porsche', 'Audi', 'Lexus', 'Audi'] cars after remove operations... cars: ['Porsche', 'Lexus', 'Audi']

Note: If any element doesn't exist in the list, method returns "ValueError".

注意:如果列表中不存在任何元素,則方法返回“ ValueError”。

Example 2:

范例2:

# Python List remove() Method with Example# declaring the list x = [10, 20, 30, 40, 50, 60, 70]# printing the list print("x before remove operations...") print("x: ", x)x.remove(10) # will remove 10 x.remove(70) # will remove 70# printing the list print("x after remove operations...") print("x: ", x)# removing an element that doesn't exist # in the list... x.remove(100) # will generate error

Output

輸出量

x before remove operations... x: [10, 20, 30, 40, 50, 60, 70] x after remove operations... x: [20, 30, 40, 50, 60] Traceback (most recent call last):File "main.py", line 19, in <module>x.remove(100) # will generate error ValueError: list.remove(x): x not in list

翻譯自: https://www.includehelp.com/python/list-remove-method-with-example.aspx

python 示例

總結(jié)

以上是生活随笔為你收集整理的python 示例_带有示例的Python列表remove()方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。