[{"data":1,"prerenderedAt":1398},["ShallowReactive",2],{"doc-\u002Freference\u002Fpython-list-clear-method":3},{"id":4,"title":5,"body":6,"description":1391,"extension":1392,"meta":1393,"navigation":243,"path":1394,"seo":1395,"stem":1396,"__hash__":1397},"content\u002Freference\u002Fpython-list-clear-method.md","Python List clear() Method",{"type":7,"value":8,"toc":1355},"minimark",[9,19,26,34,39,118,124,131,136,155,161,165,168,184,187,198,202,205,273,276,285,288,304,312,316,324,331,426,429,478,487,495,498,512,527,534,613,622,629,703,712,715,726,737,743,748,759,762,839,860,864,875,878,927,929,951,954,957,1008,1015,1022,1089,1096,1102,1105,1136,1142,1148,1151,1229,1232,1243,1250,1254,1261,1264,1270,1276,1285,1293,1300,1306,1310,1351],[10,11,13,14,18],"h1",{"id":12},"python-list-clear-method","Python List ",[15,16,17],"code",{},"clear()"," Method",[20,21,22,25],"p",{},[15,23,24],{},"list.clear()"," removes every item from a list.",[20,27,28,29,33],{},"Use it when you want to empty an existing list ",[30,31,32],"strong",{},"in place",". This is useful when you want to keep using the same list object, but remove all of its contents.",[35,36,38],"h2",{"id":37},"quick-answer","Quick answer",[40,41,46],"pre",{"className":42,"code":43,"language":44,"meta":45,"style":45},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","items = [1, 2, 3]\nitems.clear()\nprint(items)  # []\n","python","",[15,47,48,83,99],{"__ignoreMap":45},[49,50,53,57,61,65,69,72,75,77,80],"span",{"class":51,"line":52},"line",1,[49,54,56],{"class":55},"su5hD","items ",[49,58,60],{"class":59},"smGrS","=",[49,62,64],{"class":63},"sP7_E"," [",[49,66,68],{"class":67},"srdBf","1",[49,70,71],{"class":63},",",[49,73,74],{"class":67}," 2",[49,76,71],{"class":63},[49,78,79],{"class":67}," 3",[49,81,82],{"class":63},"]\n",[49,84,86,89,92,96],{"class":51,"line":85},2,[49,87,88],{"class":55},"items",[49,90,91],{"class":63},".",[49,93,95],{"class":94},"slqww","clear",[49,97,98],{"class":63},"()\n",[49,100,102,106,109,111,114],{"class":51,"line":101},3,[49,103,105],{"class":104},"sptTA","print",[49,107,108],{"class":63},"(",[49,110,88],{"class":94},[49,112,113],{"class":63},")",[49,115,117],{"class":116},"sutJx","  # []\n",[20,119,120,121,123],{},"Use ",[15,122,17],{}," to remove all items from an existing list in place.",[35,125,127,128,130],{"id":126},"what-listclear-does","What ",[15,129,24],{}," does",[20,132,133,135],{},[15,134,24],{},":",[137,138,139,143,146,152],"ul",{},[140,141,142],"li",{},"Removes every item from a list",[140,144,145],{},"Changes the original list in place",[140,147,148,149],{},"Leaves you with an empty list: ",[15,150,151],{},"[]",[140,153,154],{},"Takes no arguments",[20,156,157,158,160],{},"This means the list still exists after calling ",[15,159,17],{},", but it contains no values.",[35,162,164],{"id":163},"basic-syntax","Basic syntax",[20,166,167],{},"Syntax:",[40,169,171],{"className":42,"code":170,"language":44,"meta":45,"style":45},"my_list.clear()\n",[15,172,173],{"__ignoreMap":45},[49,174,175,178,180,182],{"class":51,"line":52},[49,176,177],{"class":55},"my_list",[49,179,91],{"class":63},[49,181,95],{"class":94},[49,183,98],{"class":63},[20,185,186],{},"Important points:",[137,188,189,192,195],{},[140,190,191],{},"Call it on a list object",[140,193,194],{},"Do not pass values inside the parentheses",[140,196,197],{},"Include the parentheses so the method actually runs",[35,199,201],{"id":200},"simple-example","Simple example",[20,203,204],{},"Here is a basic example:",[40,206,208],{"className":42,"code":207,"language":44,"meta":45,"style":45},"numbers = [10, 20, 30, 40]\n\nnumbers.clear()\n\nprint(numbers)\n",[15,209,210,239,245,256,261],{"__ignoreMap":45},[49,211,212,215,217,219,222,224,227,229,232,234,237],{"class":51,"line":52},[49,213,214],{"class":55},"numbers ",[49,216,60],{"class":59},[49,218,64],{"class":63},[49,220,221],{"class":67},"10",[49,223,71],{"class":63},[49,225,226],{"class":67}," 20",[49,228,71],{"class":63},[49,230,231],{"class":67}," 30",[49,233,71],{"class":63},[49,235,236],{"class":67}," 40",[49,238,82],{"class":63},[49,240,241],{"class":51,"line":85},[49,242,244],{"emptyLinePlaceholder":243},true,"\n",[49,246,247,250,252,254],{"class":51,"line":101},[49,248,249],{"class":55},"numbers",[49,251,91],{"class":63},[49,253,95],{"class":94},[49,255,98],{"class":63},[49,257,259],{"class":51,"line":258},4,[49,260,244],{"emptyLinePlaceholder":243},[49,262,264,266,268,270],{"class":51,"line":263},5,[49,265,105],{"class":104},[49,267,108],{"class":63},[49,269,249],{"class":94},[49,271,272],{"class":63},")\n",[20,274,275],{},"Output:",[40,277,279],{"className":42,"code":278,"language":44,"meta":45,"style":45},"[]\n",[15,280,281],{"__ignoreMap":45},[49,282,283],{"class":51,"line":52},[49,284,278],{"class":63},[20,286,287],{},"What happens here:",[137,289,290,295,301],{},[140,291,292,294],{},[15,293,249],{}," starts with four items",[140,296,297,300],{},[15,298,299],{},"numbers.clear()"," removes all of them",[140,302,303],{},"Printing the list shows that it is now empty",[20,305,306,307,91],{},"If you are new to lists, see ",[308,309,311],"a",{"href":310},"\u002Flearn\u002Fpython-lists-explained-beginner-guide","Python lists explained for beginners",[35,313,315],{"id":314},"return-value","Return value",[20,317,318,320,321,91],{},[15,319,17],{}," returns ",[15,322,323],{},"None",[20,325,326,327,330],{},"It does ",[30,328,329],{},"not"," create a new list.",[40,332,334],{"className":42,"code":333,"language":44,"meta":45,"style":45},"items = [\"a\", \"b\", \"c\"]\n\nresult = items.clear()\n\nprint(items)   # []\nprint(result)  # None\n",[15,335,336,374,378,394,398,411],{"__ignoreMap":45},[49,337,338,340,342,344,348,351,353,355,358,361,363,365,367,370,372],{"class":51,"line":52},[49,339,56],{"class":55},[49,341,60],{"class":59},[49,343,64],{"class":63},[49,345,347],{"class":346},"sjJ54","\"",[49,349,308],{"class":350},"s_sjI",[49,352,347],{"class":346},[49,354,71],{"class":63},[49,356,357],{"class":346}," \"",[49,359,360],{"class":350},"b",[49,362,347],{"class":346},[49,364,71],{"class":63},[49,366,357],{"class":346},[49,368,369],{"class":350},"c",[49,371,347],{"class":346},[49,373,82],{"class":63},[49,375,376],{"class":51,"line":85},[49,377,244],{"emptyLinePlaceholder":243},[49,379,380,383,385,388,390,392],{"class":51,"line":101},[49,381,382],{"class":55},"result ",[49,384,60],{"class":59},[49,386,387],{"class":55}," items",[49,389,91],{"class":63},[49,391,95],{"class":94},[49,393,98],{"class":63},[49,395,396],{"class":51,"line":258},[49,397,244],{"emptyLinePlaceholder":243},[49,399,400,402,404,406,408],{"class":51,"line":263},[49,401,105],{"class":104},[49,403,108],{"class":63},[49,405,88],{"class":94},[49,407,113],{"class":63},[49,409,410],{"class":116},"   # []\n",[49,412,414,416,418,421,423],{"class":51,"line":413},6,[49,415,105],{"class":104},[49,417,108],{"class":63},[49,419,420],{"class":94},"result",[49,422,113],{"class":63},[49,424,425],{"class":116},"  # None\n",[20,427,428],{},"This is a common beginner mistake. If you write:",[40,430,432],{"className":42,"code":431,"language":44,"meta":45,"style":45},"items = [1, 2, 3]\nitems = items.clear()\nprint(items)\n",[15,433,434,454,468],{"__ignoreMap":45},[49,435,436,438,440,442,444,446,448,450,452],{"class":51,"line":52},[49,437,56],{"class":55},[49,439,60],{"class":59},[49,441,64],{"class":63},[49,443,68],{"class":67},[49,445,71],{"class":63},[49,447,74],{"class":67},[49,449,71],{"class":63},[49,451,79],{"class":67},[49,453,82],{"class":63},[49,455,456,458,460,462,464,466],{"class":51,"line":85},[49,457,56],{"class":55},[49,459,60],{"class":59},[49,461,387],{"class":55},[49,463,91],{"class":63},[49,465,95],{"class":94},[49,467,98],{"class":63},[49,469,470,472,474,476],{"class":51,"line":101},[49,471,105],{"class":104},[49,473,108],{"class":63},[49,475,88],{"class":94},[49,477,272],{"class":63},[20,479,480,481,483,484,486],{},"Then ",[15,482,88],{}," becomes ",[15,485,323],{},", not an empty list.",[35,488,490,492,493],{"id":489},"clear-vs-assigning",[15,491,17],{}," vs assigning ",[15,494,151],{},[20,496,497],{},"These two lines may look similar, but they are not the same:",[40,499,500],{"className":42,"code":170,"language":44,"meta":45,"style":45},[15,501,502],{"__ignoreMap":45},[49,503,504,506,508,510],{"class":51,"line":52},[49,505,177],{"class":55},[49,507,91],{"class":63},[49,509,95],{"class":94},[49,511,98],{"class":63},[40,513,515],{"className":42,"code":514,"language":44,"meta":45,"style":45},"my_list = []\n",[15,516,517],{"__ignoreMap":45},[49,518,519,522,524],{"class":51,"line":52},[49,520,521],{"class":55},"my_list ",[49,523,60],{"class":59},[49,525,526],{"class":63}," []\n",[528,529,531,533],"h3",{"id":530},"clear-empties-the-same-list-object",[15,532,17],{}," empties the same list object",[40,535,537],{"className":42,"code":536,"language":44,"meta":45,"style":45},"a = [1, 2, 3]\nb = a\n\na.clear()\n\nprint(a)  # []\nprint(b)  # []\n",[15,538,539,560,570,574,584,588,600],{"__ignoreMap":45},[49,540,541,544,546,548,550,552,554,556,558],{"class":51,"line":52},[49,542,543],{"class":55},"a ",[49,545,60],{"class":59},[49,547,64],{"class":63},[49,549,68],{"class":67},[49,551,71],{"class":63},[49,553,74],{"class":67},[49,555,71],{"class":63},[49,557,79],{"class":67},[49,559,82],{"class":63},[49,561,562,565,567],{"class":51,"line":85},[49,563,564],{"class":55},"b ",[49,566,60],{"class":59},[49,568,569],{"class":55}," a\n",[49,571,572],{"class":51,"line":101},[49,573,244],{"emptyLinePlaceholder":243},[49,575,576,578,580,582],{"class":51,"line":258},[49,577,308],{"class":55},[49,579,91],{"class":63},[49,581,95],{"class":94},[49,583,98],{"class":63},[49,585,586],{"class":51,"line":263},[49,587,244],{"emptyLinePlaceholder":243},[49,589,590,592,594,596,598],{"class":51,"line":413},[49,591,105],{"class":104},[49,593,108],{"class":63},[49,595,308],{"class":94},[49,597,113],{"class":63},[49,599,117],{"class":116},[49,601,603,605,607,609,611],{"class":51,"line":602},7,[49,604,105],{"class":104},[49,606,108],{"class":63},[49,608,360],{"class":94},[49,610,113],{"class":63},[49,612,117],{"class":116},[20,614,615,616,618,619,621],{},"Both ",[15,617,308],{}," and ",[15,620,360],{}," point to the same list, so clearing it affects both variables.",[528,623,625,628],{"id":624},"my_list-creates-a-new-empty-list",[15,626,627],{},"my_list = []"," creates a new empty list",[40,630,632],{"className":42,"code":631,"language":44,"meta":45,"style":45},"a = [1, 2, 3]\nb = a\n\na = []\n\nprint(a)  # []\nprint(b)  # [1, 2, 3]\n",[15,633,634,654,662,666,674,678,690],{"__ignoreMap":45},[49,635,636,638,640,642,644,646,648,650,652],{"class":51,"line":52},[49,637,543],{"class":55},[49,639,60],{"class":59},[49,641,64],{"class":63},[49,643,68],{"class":67},[49,645,71],{"class":63},[49,647,74],{"class":67},[49,649,71],{"class":63},[49,651,79],{"class":67},[49,653,82],{"class":63},[49,655,656,658,660],{"class":51,"line":85},[49,657,564],{"class":55},[49,659,60],{"class":59},[49,661,569],{"class":55},[49,663,664],{"class":51,"line":101},[49,665,244],{"emptyLinePlaceholder":243},[49,667,668,670,672],{"class":51,"line":258},[49,669,543],{"class":55},[49,671,60],{"class":59},[49,673,526],{"class":63},[49,675,676],{"class":51,"line":263},[49,677,244],{"emptyLinePlaceholder":243},[49,679,680,682,684,686,688],{"class":51,"line":413},[49,681,105],{"class":104},[49,683,108],{"class":63},[49,685,308],{"class":94},[49,687,113],{"class":63},[49,689,117],{"class":116},[49,691,692,694,696,698,700],{"class":51,"line":602},[49,693,105],{"class":104},[49,695,108],{"class":63},[49,697,360],{"class":94},[49,699,113],{"class":63},[49,701,702],{"class":116},"  # [1, 2, 3]\n",[20,704,705,706,708,709,711],{},"Here, ",[15,707,308],{}," now points to a new empty list. But ",[15,710,360],{}," still points to the original list.",[20,713,714],{},"This difference matters when:",[137,716,717,720,723],{},[140,718,719],{},"Two variables refer to the same list",[140,721,722],{},"A list is shared between parts of a program",[140,724,725],{},"You want to empty the original list instead of replacing it",[20,727,728,729,91],{},"This idea is also helpful when learning ",[308,730,732,733,736],{"href":731},"\u002Freference\u002Fpython-list-copy-method\u002F","the list ",[15,734,735],{},"copy()"," method",[35,738,740,741],{"id":739},"when-to-use-clear","When to use ",[15,742,17],{},[20,744,120,745,747],{},[15,746,17],{}," when you want to:",[137,749,750,753,756],{},[140,751,752],{},"Reset a list before reusing it",[140,754,755],{},"Empty shared list data in place",[140,757,758],{},"Remove all items without deleting the list variable",[20,760,761],{},"Example:",[40,763,765],{"className":42,"code":764,"language":44,"meta":45,"style":45},"shopping_cart = [\"milk\", \"bread\", \"eggs\"]\n\n# Order completed, reuse the same list\nshopping_cart.clear()\n\nprint(shopping_cart)  # []\n",[15,766,767,803,807,812,823,827],{"__ignoreMap":45},[49,768,769,772,774,776,778,781,783,785,787,790,792,794,796,799,801],{"class":51,"line":52},[49,770,771],{"class":55},"shopping_cart ",[49,773,60],{"class":59},[49,775,64],{"class":63},[49,777,347],{"class":346},[49,779,780],{"class":350},"milk",[49,782,347],{"class":346},[49,784,71],{"class":63},[49,786,357],{"class":346},[49,788,789],{"class":350},"bread",[49,791,347],{"class":346},[49,793,71],{"class":63},[49,795,357],{"class":346},[49,797,798],{"class":350},"eggs",[49,800,347],{"class":346},[49,802,82],{"class":63},[49,804,805],{"class":51,"line":85},[49,806,244],{"emptyLinePlaceholder":243},[49,808,809],{"class":51,"line":101},[49,810,811],{"class":116},"# Order completed, reuse the same list\n",[49,813,814,817,819,821],{"class":51,"line":258},[49,815,816],{"class":55},"shopping_cart",[49,818,91],{"class":63},[49,820,95],{"class":94},[49,822,98],{"class":63},[49,824,825],{"class":51,"line":263},[49,826,244],{"emptyLinePlaceholder":243},[49,828,829,831,833,835,837],{"class":51,"line":413},[49,830,105],{"class":104},[49,832,108],{"class":63},[49,834,816],{"class":94},[49,836,113],{"class":63},[49,838,117],{"class":116},[20,840,841,842,846,847,853,854,91],{},"If you only want to remove one item, see ",[308,843,845],{"href":844},"\u002Fhow-to\u002Fhow-to-remove-an-item-from-a-list-in-python\u002F","how to remove an item from a list in Python"," or the ",[308,848,850,736],{"href":849},"\u002Freference\u002Fpython-list-remove-method\u002F",[15,851,852],{},"list.remove()",". If you want to remove and return one item, see the ",[308,855,857,736],{"href":856},"\u002Freference\u002Fpython-list-pop-method\u002F",[15,858,859],{},"list.pop()",[35,861,863],{"id":862},"common-beginner-mistakes","Common beginner mistakes",[528,865,867,868,871,872],{"id":866},"writing-my_listclear-instead-of-my_listclear","Writing ",[15,869,870],{},"my_list.clear"," instead of ",[15,873,874],{},"my_list.clear()",[20,876,877],{},"This does not call the method.",[40,879,881],{"className":42,"code":880,"language":44,"meta":45,"style":45},"items = [1, 2, 3]\n\nitems.clear\nprint(items)\n",[15,882,883,903,907,917],{"__ignoreMap":45},[49,884,885,887,889,891,893,895,897,899,901],{"class":51,"line":52},[49,886,56],{"class":55},[49,888,60],{"class":59},[49,890,64],{"class":63},[49,892,68],{"class":67},[49,894,71],{"class":63},[49,896,74],{"class":67},[49,898,71],{"class":63},[49,900,79],{"class":67},[49,902,82],{"class":63},[49,904,905],{"class":51,"line":85},[49,906,244],{"emptyLinePlaceholder":243},[49,908,909,911,913],{"class":51,"line":101},[49,910,88],{"class":55},[49,912,91],{"class":63},[49,914,916],{"class":915},"skxfh","clear\n",[49,918,919,921,923,925],{"class":51,"line":258},[49,920,105],{"class":104},[49,922,108],{"class":63},[49,924,88],{"class":94},[49,926,272],{"class":63},[20,928,275],{},[40,930,932],{"className":42,"code":931,"language":44,"meta":45,"style":45},"[1, 2, 3]\n",[15,933,934],{"__ignoreMap":45},[49,935,936,939,941,943,945,947,949],{"class":51,"line":52},[49,937,938],{"class":63},"[",[49,940,68],{"class":67},[49,942,71],{"class":63},[49,944,74],{"class":67},[49,946,71],{"class":63},[49,948,79],{"class":67},[49,950,82],{"class":63},[20,952,953],{},"Nothing changes because the method was not run.",[20,955,956],{},"Correct version:",[40,958,960],{"className":42,"code":959,"language":44,"meta":45,"style":45},"items = [1, 2, 3]\n\nitems.clear()\nprint(items)  # []\n",[15,961,962,982,986,996],{"__ignoreMap":45},[49,963,964,966,968,970,972,974,976,978,980],{"class":51,"line":52},[49,965,56],{"class":55},[49,967,60],{"class":59},[49,969,64],{"class":63},[49,971,68],{"class":67},[49,973,71],{"class":63},[49,975,74],{"class":67},[49,977,71],{"class":63},[49,979,79],{"class":67},[49,981,82],{"class":63},[49,983,984],{"class":51,"line":85},[49,985,244],{"emptyLinePlaceholder":243},[49,987,988,990,992,994],{"class":51,"line":101},[49,989,88],{"class":55},[49,991,91],{"class":63},[49,993,95],{"class":94},[49,995,98],{"class":63},[49,997,998,1000,1002,1004,1006],{"class":51,"line":258},[49,999,105],{"class":104},[49,1001,108],{"class":63},[49,1003,88],{"class":94},[49,1005,113],{"class":63},[49,1007,117],{"class":116},[528,1009,1011,1012,1014],{"id":1010},"expecting-clear-to-return-the-emptied-list","Expecting ",[15,1013,17],{}," to return the emptied list",[20,1016,1017,320,1019,1021],{},[15,1018,17],{},[15,1020,323],{},", not the list.",[40,1023,1025],{"className":42,"code":1024,"language":44,"meta":45,"style":45},"items = [1, 2, 3]\nresult = items.clear()\n\nprint(result)  # None\nprint(items)   # []\n",[15,1026,1027,1047,1061,1065,1077],{"__ignoreMap":45},[49,1028,1029,1031,1033,1035,1037,1039,1041,1043,1045],{"class":51,"line":52},[49,1030,56],{"class":55},[49,1032,60],{"class":59},[49,1034,64],{"class":63},[49,1036,68],{"class":67},[49,1038,71],{"class":63},[49,1040,74],{"class":67},[49,1042,71],{"class":63},[49,1044,79],{"class":67},[49,1046,82],{"class":63},[49,1048,1049,1051,1053,1055,1057,1059],{"class":51,"line":85},[49,1050,382],{"class":55},[49,1052,60],{"class":59},[49,1054,387],{"class":55},[49,1056,91],{"class":63},[49,1058,95],{"class":94},[49,1060,98],{"class":63},[49,1062,1063],{"class":51,"line":101},[49,1064,244],{"emptyLinePlaceholder":243},[49,1066,1067,1069,1071,1073,1075],{"class":51,"line":258},[49,1068,105],{"class":104},[49,1070,108],{"class":63},[49,1072,420],{"class":94},[49,1074,113],{"class":63},[49,1076,425],{"class":116},[49,1078,1079,1081,1083,1085,1087],{"class":51,"line":263},[49,1080,105],{"class":104},[49,1082,108],{"class":63},[49,1084,88],{"class":94},[49,1086,113],{"class":63},[49,1088,410],{"class":116},[528,1090,1092,1093,1095],{"id":1091},"using-clear-on-a-value-that-is-not-a-list","Using ",[15,1094,17],{}," on a value that is not a list",[20,1097,1098,1099,1101],{},"Some types have a ",[15,1100,17],{}," method, but not all of them.",[20,1103,1104],{},"This will fail:",[40,1106,1108],{"className":42,"code":1107,"language":44,"meta":45,"style":45},"text = \"hello\"\ntext.clear()\n",[15,1109,1110,1125],{"__ignoreMap":45},[49,1111,1112,1115,1117,1119,1122],{"class":51,"line":52},[49,1113,1114],{"class":55},"text ",[49,1116,60],{"class":59},[49,1118,357],{"class":346},[49,1120,1121],{"class":350},"hello",[49,1123,1124],{"class":346},"\"\n",[49,1126,1127,1130,1132,1134],{"class":51,"line":85},[49,1128,1129],{"class":55},"text",[49,1131,91],{"class":63},[49,1133,95],{"class":94},[49,1135,98],{"class":63},[20,1137,1138,1139,1141],{},"A string does not have a ",[15,1140,17],{}," method.",[20,1143,1144,1145,1147],{},"You may also get errors if your variable is ",[15,1146,323],{}," or another unexpected type. If that happens, print the type first.",[20,1149,1150],{},"Useful checks:",[40,1152,1154],{"className":42,"code":1153,"language":44,"meta":45,"style":45},"print(my_list)\nprint(type(my_list))\nprint(id(my_list))\nother = my_list\nmy_list.clear()\nprint(other)\n",[15,1155,1156,1166,1183,1198,1208,1218],{"__ignoreMap":45},[49,1157,1158,1160,1162,1164],{"class":51,"line":52},[49,1159,105],{"class":104},[49,1161,108],{"class":63},[49,1163,177],{"class":94},[49,1165,272],{"class":63},[49,1167,1168,1170,1172,1176,1178,1180],{"class":51,"line":85},[49,1169,105],{"class":104},[49,1171,108],{"class":63},[49,1173,1175],{"class":1174},"sZMiF","type",[49,1177,108],{"class":63},[49,1179,177],{"class":94},[49,1181,1182],{"class":63},"))\n",[49,1184,1185,1187,1189,1192,1194,1196],{"class":51,"line":101},[49,1186,105],{"class":104},[49,1188,108],{"class":63},[49,1190,1191],{"class":104},"id",[49,1193,108],{"class":63},[49,1195,177],{"class":94},[49,1197,1182],{"class":63},[49,1199,1200,1203,1205],{"class":51,"line":258},[49,1201,1202],{"class":55},"other ",[49,1204,60],{"class":59},[49,1206,1207],{"class":55}," my_list\n",[49,1209,1210,1212,1214,1216],{"class":51,"line":263},[49,1211,177],{"class":55},[49,1213,91],{"class":63},[49,1215,95],{"class":94},[49,1217,98],{"class":63},[49,1219,1220,1222,1224,1227],{"class":51,"line":413},[49,1221,105],{"class":104},[49,1223,108],{"class":63},[49,1225,1226],{"class":94},"other",[49,1228,272],{"class":63},[20,1230,1231],{},"These can help you see:",[137,1233,1234,1237,1240],{},[140,1235,1236],{},"What the variable currently contains",[140,1238,1239],{},"Whether it is really a list",[140,1241,1242],{},"Whether two variables point to the same object",[20,1244,1245,1246,91],{},"If you run into method-related problems, you may also need help with ",[308,1247,1249],{"href":1248},"\u002Ferrors\u002Fattributeerror-list-object-has-no-attribute-fix\u002F","fixing attribute errors in Python",[35,1251,1253],{"id":1252},"faq","FAQ",[528,1255,1257,1258,1260],{"id":1256},"does-listclear-delete-the-list","Does ",[15,1259,24],{}," delete the list?",[20,1262,1263],{},"No. It keeps the list object but removes all items from it.",[528,1265,1257,1267,1269],{"id":1266},"does-listclear-return-a-new-list",[15,1268,24],{}," return a new list?",[20,1271,1272,1273,1275],{},"No. It returns ",[15,1274,323],{}," and changes the existing list in place.",[528,1277,1279,1280,618,1282,1284],{"id":1278},"what-is-the-difference-between-clear-and-my_list","What is the difference between ",[15,1281,17],{},[15,1283,627],{},"?",[20,1286,1287,1289,1290,1292],{},[15,1288,17],{}," empties the same list object. ",[15,1291,627],{}," points the variable to a new empty list.",[528,1294,1296,1297,1299],{"id":1295},"can-i-use-clear-on-other-types","Can I use ",[15,1298,17],{}," on other types?",[20,1301,1302,1303,1305],{},"Some types like dictionaries and sets also have ",[15,1304,17],{},", but strings and tuples do not.",[35,1307,1309],{"id":1308},"see-also","See also",[137,1311,1312,1316,1321,1329,1336,1342],{},[140,1313,1314],{},[308,1315,311],{"href":310},[140,1317,1318],{},[308,1319,1320],{"href":844},"How to remove an item from a list in Python",[140,1322,1323],{},[308,1324,1325,1326,736],{"href":856},"Python list ",[15,1327,1328],{},"pop()",[140,1330,1331],{},[308,1332,1325,1333,736],{"href":849},[15,1334,1335],{},"remove()",[140,1337,1338],{},[308,1339,1325,1340,736],{"href":731},[15,1341,735],{},[140,1343,1344],{},[308,1345,1346,1347,1350],{"href":1248},"Fix ",[15,1348,1349],{},"'list' object has no attribute"," errors",[1352,1353,1354],"style",{},"html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":45,"searchDepth":85,"depth":85,"links":1356},[1357,1358,1360,1361,1362,1363,1370,1372,1380,1390],{"id":37,"depth":85,"text":38},{"id":126,"depth":85,"text":1359},"What list.clear() does",{"id":163,"depth":85,"text":164},{"id":200,"depth":85,"text":201},{"id":314,"depth":85,"text":315},{"id":489,"depth":85,"text":1364,"children":1365},"clear() vs assigning []",[1366,1368],{"id":530,"depth":101,"text":1367},"clear() empties the same list object",{"id":624,"depth":101,"text":1369},"my_list = [] creates a new empty list",{"id":739,"depth":85,"text":1371},"When to use clear()",{"id":862,"depth":85,"text":863,"children":1373},[1374,1376,1378],{"id":866,"depth":101,"text":1375},"Writing my_list.clear instead of my_list.clear()",{"id":1010,"depth":101,"text":1377},"Expecting clear() to return the emptied list",{"id":1091,"depth":101,"text":1379},"Using clear() on a value that is not a list",{"id":1252,"depth":85,"text":1253,"children":1381},[1382,1384,1386,1388],{"id":1256,"depth":101,"text":1383},"Does list.clear() delete the list?",{"id":1266,"depth":101,"text":1385},"Does list.clear() return a new list?",{"id":1278,"depth":101,"text":1387},"What is the difference between clear() and my_list = []?",{"id":1295,"depth":101,"text":1389},"Can I use clear() on other types?",{"id":1308,"depth":85,"text":1309},"Master python list clear method in our comprehensive Python beginner guide.","md",{},"\u002Freference\u002Fpython-list-clear-method",{"title":5,"description":1391},"reference\u002Fpython-list-clear-method","99lr7F7Fwd7-AwSOSGz-bBA8zQ5YwXwJzSYBs0JP2O4",1777585489380]