{"id":24714,"date":"2021-11-02T09:45:53","date_gmt":"2021-11-02T04:15:53","guid":{"rendered":"https:\/\/python-programs.com\/?p=24714"},"modified":"2021-11-05T17:22:06","modified_gmt":"2021-11-05T11:52:06","slug":"python-list-remove-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-list-remove-method-with-examples\/","title":{"rendered":"Python List remove() Method with Examples"},"content":{"rendered":"
In the previous article, we have discussed Python List pop() Method with Examples<\/a> Lists in Python are mutable sequences. They are extremely similar to tuples, except they do not have immutability constraints. Lists are often used to store collections of homogeneous things, but there is nothing stopping you from storing collections of heterogeneous items as well.<\/p>\n List remove() Method in Python:<\/strong><\/p>\n The remove() method deletes the element’s first occurrence with the specified value.<\/p>\n Syntax:<\/strong><\/p>\n Parameters<\/strong><\/p>\n Return Value:<\/strong><\/p>\n This function does not return any value.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Covered all examples on python concepts and missed checking out the Python List Method Examples<\/a> then go with the available link & gain more knowledge about List method concepts in python.<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" In the previous article, we have discussed Python List pop() Method with Examples List in Python: Lists in Python are mutable sequences. They are extremely similar to tuples, except they do not have immutability constraints. Lists are often used to store collections of homogeneous things, but there is nothing stopping you from storing collections of …<\/p>\n
\nList in Python:<\/strong><\/p>\nlist.remove(element)<\/pre>\n
\n
Given List = ['hello', 'this', 'is', 'btechgeeks']\r\nGiven element to be removed = 'hello'<\/pre>\n
The given original list is: ['hello', 'this', 'is', 'btechgeeks']\r\nThe given list after removing the given element{ hello } is :\r\n['this', 'is', 'btechgeeks']<\/pre>\n
Given List = [-1, 0, 2, 8, 9, 2]\r\nGiven element to be removed = 2<\/pre>\n
The given original list is: [-1, 0, 2, 8, 9, 2]\r\nThe given list after removing the given element{ 2 } is :\r\n[-1, 0, 8, 9, 2]<\/pre>\n
List remove() Method with Examples in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Give the list as static input and store it in a variable.\r\ngvn_lst = ['hello', 'this', 'is', 'btechgeeks']\r\n# Print the given original list.\r\nprint(\"The given original list is:\", gvn_lst)\r\n# Give the element to be removed as static input and store it in another variable.\r\ngvn_elemnt = 'hello'\r\n# Pass the given element as an argument to the remove() method for the\r\n# given list that removes the given element from the given list.\r\ngvn_lst.remove(gvn_elemnt)\r\n# Print the list after removing the given element.\r\nprint(\"The given list after removing the given element{\", gvn_elemnt, \"} is :\")\r\nprint(gvn_lst)\r\n<\/pre>\n
The given original list is: ['hello', 'this', 'is', 'btechgeeks']\r\nThe given list after removing the given element{ hello } is :\r\n['this', 'is', 'btechgeeks']<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_lst = list(map(int, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Print the given original list.\r\nprint(\"The given original list is:\", gvn_lst)\r\n# Give the element to be removed as user input using the int(input()) function \r\n# and store it in another variable.\r\ngvn_elemnt = int(input(\"Enter some random number = \"))\r\n# Pass the given element as an argument to the remove() method for the\r\n# given list that removes the given element from the given list.\r\ngvn_lst.remove(gvn_elemnt)\r\n# Print the list after removing the given element.\r\nprint(\"The given list after removing the given element{\", gvn_elemnt, \"} is :\")\r\nprint(gvn_lst)\r\n<\/pre>\n
Enter some random List Elements separated by spaces = -1 0 2 8 9\r\nThe given original list is: [-1, 0, 2, 8, 9]\r\nEnter some random number = 2\r\nThe given list after removing the given element{ 2 } is :\r\n[-1, 0, 8, 9]<\/pre>\n
\n