{"id":24699,"date":"2021-10-25T09:11:20","date_gmt":"2021-10-25T03:41:20","guid":{"rendered":"https:\/\/python-programs.com\/?p=24699"},"modified":"2021-11-05T17:20:32","modified_gmt":"2021-11-05T11:50:32","slug":"python-list-clear-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-list-clear-method-with-examples\/","title":{"rendered":"Python List clear() Method with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python List append() Method with Examples<\/a>
\nList in Python:<\/strong><\/p>\n

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 clear() Method in Python:<\/strong><\/p>\n

The clear() method clears or removes all the elements from the list.<\/p>\n

Syntax:<\/strong><\/p>\n

list.clear()<\/pre>\n

Parameter Values:<\/strong> This method has no parameters.<\/p>\n

Return Value:<\/strong><\/p>\n

The clear() method only removes items from the specified list. It doesn’t return anything.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [\"good\", \"morning\", \"btechgeeks\"]<\/pre>\n

Output:<\/strong><\/p>\n

The given list is : ['good', 'morning', 'btechgeeks']\r\nThe given list after applying clear() method: []<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given list = [25, 35, 67, 12, 15]<\/pre>\n

Output:<\/strong><\/p>\n

The given list is : [25, 35, 67, 12, 15]\r\nThe given list after applying clear() method: []<\/pre>\n

List clear() Method with Examples in Python<\/h2>\n