[{"data":1,"prerenderedAt":1566},["ShallowReactive",2],{"doc-\u002Ferrors\u002Fvalueerror-empty-separator-fix":3},{"id":4,"title":5,"body":6,"description":1559,"extension":1560,"meta":1561,"navigation":117,"path":1562,"seo":1563,"stem":1564,"__hash__":1565},"content\u002Ferrors\u002Fvalueerror-empty-separator-fix.md","ValueError: empty separator (Fix)",{"type":7,"value":8,"toc":1534},"minimark",[9,13,22,27,156,159,230,241,245,250,253,274,284,288,291,337,339,356,362,366,369,372,393,399,403,408,413,465,467,503,510,516,519,562,564,597,604,611,620,625,669,671,724,728,731,757,760,871,873,968,972,975,995,998,1054,1057,1160,1163,1207,1213,1217,1220,1251,1258,1262,1265,1290,1293,1354,1360,1422,1424,1457,1461,1468,1471,1475,1480,1484,1489,1493,1496,1500,1530],[10,11,5],"h1",{"id":12},"valueerror-empty-separator-fix",[14,15,16,17,21],"p",{},"This page helps beginners fix the Python error ",[18,19,20],"code",{},"ValueError: empty separator",". It explains why it happens, shows a small example that causes it, and gives simple ways to solve it.",[23,24,26],"h2",{"id":25},"quick-fix","Quick fix",[28,29,34],"pre",{"className":30,"code":31,"language":32,"meta":33,"style":33},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","text = \"apple,banana,orange\"\nparts = text.split(\",\")  # use a real separator\nprint(parts)\n\nwords = \"one two three\".split()  # no argument splits on whitespace\nprint(words)\n","python","",[18,35,36,60,97,112,119,144],{"__ignoreMap":33},[37,38,41,45,49,53,57],"span",{"class":39,"line":40},"line",1,[37,42,44],{"class":43},"su5hD","text ",[37,46,48],{"class":47},"smGrS","=",[37,50,52],{"class":51},"sjJ54"," \"",[37,54,56],{"class":55},"s_sjI","apple,banana,orange",[37,58,59],{"class":51},"\"\n",[37,61,63,66,68,71,75,79,82,85,88,90,93],{"class":39,"line":62},2,[37,64,65],{"class":43},"parts ",[37,67,48],{"class":47},[37,69,70],{"class":43}," text",[37,72,74],{"class":73},"sP7_E",".",[37,76,78],{"class":77},"slqww","split",[37,80,81],{"class":73},"(",[37,83,84],{"class":51},"\"",[37,86,87],{"class":55},",",[37,89,84],{"class":51},[37,91,92],{"class":73},")",[37,94,96],{"class":95},"sutJx","  # use a real separator\n",[37,98,100,104,106,109],{"class":39,"line":99},3,[37,101,103],{"class":102},"sptTA","print",[37,105,81],{"class":73},[37,107,108],{"class":77},"parts",[37,110,111],{"class":73},")\n",[37,113,115],{"class":39,"line":114},4,[37,116,118],{"emptyLinePlaceholder":117},true,"\n",[37,120,122,125,127,129,132,134,136,138,141],{"class":39,"line":121},5,[37,123,124],{"class":43},"words ",[37,126,48],{"class":47},[37,128,52],{"class":51},[37,130,131],{"class":55},"one two three",[37,133,84],{"class":51},[37,135,74],{"class":73},[37,137,78],{"class":77},[37,139,140],{"class":73},"()",[37,142,143],{"class":95},"  # no argument splits on whitespace\n",[37,145,147,149,151,154],{"class":39,"line":146},6,[37,148,103],{"class":102},[37,150,81],{"class":73},[37,152,153],{"class":77},"words",[37,155,111],{"class":73},[14,157,158],{},"Output:",[28,160,162],{"className":30,"code":161,"language":32,"meta":33,"style":33},"['apple', 'banana', 'orange']\n['one', 'two', 'three']\n",[18,163,164,199],{"__ignoreMap":33},[37,165,166,169,172,175,177,179,182,185,187,189,191,194,196],{"class":39,"line":40},[37,167,168],{"class":73},"[",[37,170,171],{"class":51},"'",[37,173,174],{"class":55},"apple",[37,176,171],{"class":51},[37,178,87],{"class":73},[37,180,181],{"class":51}," '",[37,183,184],{"class":55},"banana",[37,186,171],{"class":51},[37,188,87],{"class":73},[37,190,181],{"class":51},[37,192,193],{"class":55},"orange",[37,195,171],{"class":51},[37,197,198],{"class":73},"]\n",[37,200,201,203,205,208,210,212,214,217,219,221,223,226,228],{"class":39,"line":62},[37,202,168],{"class":73},[37,204,171],{"class":51},[37,206,207],{"class":55},"one",[37,209,171],{"class":51},[37,211,87],{"class":73},[37,213,181],{"class":51},[37,215,216],{"class":55},"two",[37,218,171],{"class":51},[37,220,87],{"class":73},[37,222,181],{"class":51},[37,224,225],{"class":55},"three",[37,227,171],{"class":51},[37,229,198],{"class":73},[14,231,232,233,236,237,240],{},"Do not pass an empty string to ",[18,234,235],{},"split()",". Use a real separator like ",[18,238,239],{},"\",\""," or leave the argument out to split on whitespace.",[23,242,244],{"id":243},"what-this-error-means","What this error means",[14,246,247,249],{},[18,248,20],{}," means Python was asked to split text using an empty string.",[14,251,252],{},"This most often happens with:",[28,254,256],{"className":30,"code":255,"language":32,"meta":33,"style":33},"text.split(\"\")\n",[18,257,258],{"__ignoreMap":33},[37,259,260,263,265,267,269,272],{"class":39,"line":40},[37,261,262],{"class":43},"text",[37,264,74],{"class":73},[37,266,78],{"class":77},[37,268,81],{"class":73},[37,270,271],{"class":51},"\"\"",[37,273,111],{"class":73},[14,275,276,277,74],{},"Python does not allow an empty separator for ",[278,279,281],"a",{"href":280},"\u002Freference\u002Fpython-string-split-method\u002F",[18,282,283],{},"str.split()",[23,285,287],{"id":286},"example-that-causes-the-error","Example that causes the error",[14,289,290],{},"A common failing example is:",[28,292,294],{"className":30,"code":293,"language":32,"meta":33,"style":33},"text = \"hello\"\nparts = text.split(\"\")\nprint(parts)\n",[18,295,296,309,327],{"__ignoreMap":33},[37,297,298,300,302,304,307],{"class":39,"line":40},[37,299,44],{"class":43},[37,301,48],{"class":47},[37,303,52],{"class":51},[37,305,306],{"class":55},"hello",[37,308,59],{"class":51},[37,310,311,313,315,317,319,321,323,325],{"class":39,"line":62},[37,312,65],{"class":43},[37,314,48],{"class":47},[37,316,70],{"class":43},[37,318,74],{"class":73},[37,320,78],{"class":77},[37,322,81],{"class":73},[37,324,271],{"class":51},[37,326,111],{"class":73},[37,328,329,331,333,335],{"class":39,"line":99},[37,330,103],{"class":102},[37,332,81],{"class":73},[37,334,108],{"class":77},[37,336,111],{"class":73},[14,338,158],{},[28,340,342],{"className":30,"code":341,"language":32,"meta":33,"style":33},"ValueError: empty separator\n",[18,343,344],{"__ignoreMap":33},[37,345,346,350,353],{"class":39,"line":40},[37,347,349],{"class":348},"sZMiF","ValueError",[37,351,352],{"class":73},":",[37,354,355],{"class":43}," empty separator\n",[14,357,358,359,74],{},"The problem is the empty string inside ",[18,360,361],{},"split(\"\")",[23,363,365],{"id":364},"why-it-happens","Why it happens",[14,367,368],{},"A separator must be at least one character long.",[14,370,371],{},"Python needs a real boundary such as:",[373,374,375,382,387],"ul",{},[376,377,378,379],"li",{},"a space: ",[18,380,381],{},"\" \"",[376,383,384,385],{},"a comma: ",[18,386,239],{},[376,388,389,390],{},"a dash: ",[18,391,392],{},"\"-\"",[14,394,395,396,398],{},"An empty string ",[18,397,271],{}," does not give Python a valid place to split.",[23,400,402],{"id":401},"how-to-fix-it","How to fix it",[404,405,407],"h3",{"id":406},"use-a-real-separator","Use a real separator",[14,409,410,411,74],{},"If your text uses commas, spaces, or another character between values, pass that character to ",[18,412,235],{},[28,414,416],{"className":30,"code":415,"language":32,"meta":33,"style":33},"text = \"red,green,blue\"\ncolors = text.split(\",\")\nprint(colors)\n",[18,417,418,431,454],{"__ignoreMap":33},[37,419,420,422,424,426,429],{"class":39,"line":40},[37,421,44],{"class":43},[37,423,48],{"class":47},[37,425,52],{"class":51},[37,427,428],{"class":55},"red,green,blue",[37,430,59],{"class":51},[37,432,433,436,438,440,442,444,446,448,450,452],{"class":39,"line":62},[37,434,435],{"class":43},"colors ",[37,437,48],{"class":47},[37,439,70],{"class":43},[37,441,74],{"class":73},[37,443,78],{"class":77},[37,445,81],{"class":73},[37,447,84],{"class":51},[37,449,87],{"class":55},[37,451,84],{"class":51},[37,453,111],{"class":73},[37,455,456,458,460,463],{"class":39,"line":99},[37,457,103],{"class":102},[37,459,81],{"class":73},[37,461,462],{"class":77},"colors",[37,464,111],{"class":73},[14,466,158],{},[28,468,470],{"className":30,"code":469,"language":32,"meta":33,"style":33},"['red', 'green', 'blue']\n",[18,471,472],{"__ignoreMap":33},[37,473,474,476,478,481,483,485,487,490,492,494,496,499,501],{"class":39,"line":40},[37,475,168],{"class":73},[37,477,171],{"class":51},[37,479,480],{"class":55},"red",[37,482,171],{"class":51},[37,484,87],{"class":73},[37,486,181],{"class":51},[37,488,489],{"class":55},"green",[37,491,171],{"class":51},[37,493,87],{"class":73},[37,495,181],{"class":51},[37,497,498],{"class":55},"blue",[37,500,171],{"class":51},[37,502,198],{"class":73},[404,504,506,507,509],{"id":505},"use-split-with-no-argument-for-whitespace","Use ",[18,508,235],{}," with no argument for whitespace",[14,511,512,513,515],{},"If you want to split words in a sentence, do not use ",[18,514,381],{}," unless you specifically need a single-space separator.",[14,517,518],{},"Use:",[28,520,522],{"className":30,"code":521,"language":32,"meta":33,"style":33},"text = \"one two   three\"\nwords = text.split()\nprint(words)\n",[18,523,524,537,552],{"__ignoreMap":33},[37,525,526,528,530,532,535],{"class":39,"line":40},[37,527,44],{"class":43},[37,529,48],{"class":47},[37,531,52],{"class":51},[37,533,534],{"class":55},"one two   three",[37,536,59],{"class":51},[37,538,539,541,543,545,547,549],{"class":39,"line":62},[37,540,124],{"class":43},[37,542,48],{"class":47},[37,544,70],{"class":43},[37,546,74],{"class":73},[37,548,78],{"class":77},[37,550,551],{"class":73},"()\n",[37,553,554,556,558,560],{"class":39,"line":99},[37,555,103],{"class":102},[37,557,81],{"class":73},[37,559,153],{"class":77},[37,561,111],{"class":73},[14,563,158],{},[28,565,567],{"className":30,"code":566,"language":32,"meta":33,"style":33},"['one', 'two', 'three']\n",[18,568,569],{"__ignoreMap":33},[37,570,571,573,575,577,579,581,583,585,587,589,591,593,595],{"class":39,"line":40},[37,572,168],{"class":73},[37,574,171],{"class":51},[37,576,207],{"class":55},[37,578,171],{"class":51},[37,580,87],{"class":73},[37,582,181],{"class":51},[37,584,216],{"class":55},[37,586,171],{"class":51},[37,588,87],{"class":73},[37,590,181],{"class":51},[37,592,225],{"class":55},[37,594,171],{"class":51},[37,596,198],{"class":73},[14,598,599,600,74],{},"This is the usual solution for splitting text into words. You can learn more in ",[278,601,603],{"href":602},"\u002Fhow-to\u002Fhow-to-split-a-string-in-python\u002F","how to split a string in Python",[404,605,506,607,610],{"id":606},"use-listtext-for-individual-characters",[18,608,609],{},"list(text)"," for individual characters",[14,612,613,614,616,617,619],{},"Some beginners expect ",[18,615,361],{}," to return each character. That is not how ",[18,618,235],{}," works.",[14,621,622,623,352],{},"If you want characters, use ",[18,624,609],{},[28,626,628],{"className":30,"code":627,"language":32,"meta":33,"style":33},"text = \"hello\"\nchars = list(text)\nprint(chars)\n",[18,629,630,642,658],{"__ignoreMap":33},[37,631,632,634,636,638,640],{"class":39,"line":40},[37,633,44],{"class":43},[37,635,48],{"class":47},[37,637,52],{"class":51},[37,639,306],{"class":55},[37,641,59],{"class":51},[37,643,644,647,649,652,654,656],{"class":39,"line":62},[37,645,646],{"class":43},"chars ",[37,648,48],{"class":47},[37,650,651],{"class":348}," list",[37,653,81],{"class":73},[37,655,262],{"class":77},[37,657,111],{"class":73},[37,659,660,662,664,667],{"class":39,"line":99},[37,661,103],{"class":102},[37,663,81],{"class":73},[37,665,666],{"class":77},"chars",[37,668,111],{"class":73},[14,670,158],{},[28,672,674],{"className":30,"code":673,"language":32,"meta":33,"style":33},"['h', 'e', 'l', 'l', 'o']\n",[18,675,676],{"__ignoreMap":33},[37,677,678,680,682,685,687,689,691,694,696,698,700,703,705,707,709,711,713,715,717,720,722],{"class":39,"line":40},[37,679,168],{"class":73},[37,681,171],{"class":51},[37,683,684],{"class":55},"h",[37,686,171],{"class":51},[37,688,87],{"class":73},[37,690,181],{"class":51},[37,692,693],{"class":55},"e",[37,695,171],{"class":51},[37,697,87],{"class":73},[37,699,181],{"class":51},[37,701,702],{"class":55},"l",[37,704,171],{"class":51},[37,706,87],{"class":73},[37,708,181],{"class":51},[37,710,702],{"class":55},[37,712,171],{"class":51},[37,714,87],{"class":73},[37,716,181],{"class":51},[37,718,719],{"class":55},"o",[37,721,171],{"class":51},[37,723,198],{"class":73},[23,725,727],{"id":726},"choose-the-right-fix-for-your-goal","Choose the right fix for your goal",[14,729,730],{},"Use the fix that matches what you want to do:",[373,732,733,742,750],{},[376,734,735,739,740],{},[736,737,738],"strong",{},"To split words in a sentence",", use ",[18,741,235],{},[376,743,744,739,747],{},[736,745,746],{},"To split comma-separated values",[18,748,749],{},"split(\",\")",[376,751,752,739,755],{},[736,753,754],{},"To turn a string into characters",[18,756,609],{},[14,758,759],{},"Examples:",[28,761,763],{"className":30,"code":762,"language":32,"meta":33,"style":33},"sentence = \"Python is fun\"\nprint(sentence.split())\n\ncsv_text = \"a,b,c\"\nprint(csv_text.split(\",\"))\n\ntext = \"cat\"\nprint(list(text))\n",[18,764,765,779,795,799,813,837,841,855],{"__ignoreMap":33},[37,766,767,770,772,774,777],{"class":39,"line":40},[37,768,769],{"class":43},"sentence ",[37,771,48],{"class":47},[37,773,52],{"class":51},[37,775,776],{"class":55},"Python is fun",[37,778,59],{"class":51},[37,780,781,783,785,788,790,792],{"class":39,"line":62},[37,782,103],{"class":102},[37,784,81],{"class":73},[37,786,787],{"class":77},"sentence",[37,789,74],{"class":73},[37,791,78],{"class":77},[37,793,794],{"class":73},"())\n",[37,796,797],{"class":39,"line":99},[37,798,118],{"emptyLinePlaceholder":117},[37,800,801,804,806,808,811],{"class":39,"line":114},[37,802,803],{"class":43},"csv_text ",[37,805,48],{"class":47},[37,807,52],{"class":51},[37,809,810],{"class":55},"a,b,c",[37,812,59],{"class":51},[37,814,815,817,819,822,824,826,828,830,832,834],{"class":39,"line":121},[37,816,103],{"class":102},[37,818,81],{"class":73},[37,820,821],{"class":77},"csv_text",[37,823,74],{"class":73},[37,825,78],{"class":77},[37,827,81],{"class":73},[37,829,84],{"class":51},[37,831,87],{"class":55},[37,833,84],{"class":51},[37,835,836],{"class":73},"))\n",[37,838,839],{"class":39,"line":146},[37,840,118],{"emptyLinePlaceholder":117},[37,842,844,846,848,850,853],{"class":39,"line":843},7,[37,845,44],{"class":43},[37,847,48],{"class":47},[37,849,52],{"class":51},[37,851,852],{"class":55},"cat",[37,854,59],{"class":51},[37,856,858,860,862,865,867,869],{"class":39,"line":857},8,[37,859,103],{"class":102},[37,861,81],{"class":73},[37,863,864],{"class":348},"list",[37,866,81],{"class":73},[37,868,262],{"class":77},[37,870,836],{"class":73},[14,872,158],{},[28,874,876],{"className":30,"code":875,"language":32,"meta":33,"style":33},"['Python', 'is', 'fun']\n['a', 'b', 'c']\n['c', 'a', 't']\n",[18,877,878,909,939],{"__ignoreMap":33},[37,879,880,882,884,887,889,891,893,896,898,900,902,905,907],{"class":39,"line":40},[37,881,168],{"class":73},[37,883,171],{"class":51},[37,885,886],{"class":55},"Python",[37,888,171],{"class":51},[37,890,87],{"class":73},[37,892,181],{"class":51},[37,894,895],{"class":55},"is",[37,897,171],{"class":51},[37,899,87],{"class":73},[37,901,181],{"class":51},[37,903,904],{"class":55},"fun",[37,906,171],{"class":51},[37,908,198],{"class":73},[37,910,911,913,915,917,919,921,923,926,928,930,932,935,937],{"class":39,"line":62},[37,912,168],{"class":73},[37,914,171],{"class":51},[37,916,278],{"class":55},[37,918,171],{"class":51},[37,920,87],{"class":73},[37,922,181],{"class":51},[37,924,925],{"class":55},"b",[37,927,171],{"class":51},[37,929,87],{"class":73},[37,931,181],{"class":51},[37,933,934],{"class":55},"c",[37,936,171],{"class":51},[37,938,198],{"class":73},[37,940,941,943,945,947,949,951,953,955,957,959,961,964,966],{"class":39,"line":99},[37,942,168],{"class":73},[37,944,171],{"class":51},[37,946,934],{"class":55},[37,948,171],{"class":51},[37,950,87],{"class":73},[37,952,181],{"class":51},[37,954,278],{"class":55},[37,956,171],{"class":51},[37,958,87],{"class":73},[37,960,181],{"class":51},[37,962,963],{"class":55},"t",[37,965,171],{"class":51},[37,967,198],{"class":73},[23,969,971],{"id":970},"debugging-steps","Debugging steps",[14,973,974],{},"If the error comes from a larger program, use these steps:",[976,977,978,983,986,989],"ol",{},[376,979,980,981],{},"Find the line that calls ",[18,982,235],{},[376,984,985],{},"Check the value passed as the separator",[376,987,988],{},"Print the separator if it comes from a variable",[376,990,991,992,994],{},"Replace ",[18,993,271],{}," with a real separator or remove the argument",[14,996,997],{},"Useful debugging commands:",[28,999,1001],{"className":30,"code":1000,"language":32,"meta":33,"style":33},"print(separator)\nprint(repr(separator))\nprint(type(separator))\nprint(text)\n",[18,1002,1003,1014,1029,1044],{"__ignoreMap":33},[37,1004,1005,1007,1009,1012],{"class":39,"line":40},[37,1006,103],{"class":102},[37,1008,81],{"class":73},[37,1010,1011],{"class":77},"separator",[37,1013,111],{"class":73},[37,1015,1016,1018,1020,1023,1025,1027],{"class":39,"line":62},[37,1017,103],{"class":102},[37,1019,81],{"class":73},[37,1021,1022],{"class":102},"repr",[37,1024,81],{"class":73},[37,1026,1011],{"class":77},[37,1028,836],{"class":73},[37,1030,1031,1033,1035,1038,1040,1042],{"class":39,"line":99},[37,1032,103],{"class":102},[37,1034,81],{"class":73},[37,1036,1037],{"class":348},"type",[37,1039,81],{"class":73},[37,1041,1011],{"class":77},[37,1043,836],{"class":73},[37,1045,1046,1048,1050,1052],{"class":39,"line":114},[37,1047,103],{"class":102},[37,1049,81],{"class":73},[37,1051,262],{"class":77},[37,1053,111],{"class":73},[14,1055,1056],{},"A full example:",[28,1058,1060],{"className":30,"code":1059,"language":32,"meta":33,"style":33},"text = \"a-b-c\"\nseparator = \"\"\n\nprint(separator)\nprint(repr(separator))\nprint(type(separator))\nprint(text)\n\nparts = text.split(separator)\n",[18,1061,1062,1075,1085,1089,1099,1113,1127,1137,1141],{"__ignoreMap":33},[37,1063,1064,1066,1068,1070,1073],{"class":39,"line":40},[37,1065,44],{"class":43},[37,1067,48],{"class":47},[37,1069,52],{"class":51},[37,1071,1072],{"class":55},"a-b-c",[37,1074,59],{"class":51},[37,1076,1077,1080,1082],{"class":39,"line":62},[37,1078,1079],{"class":43},"separator ",[37,1081,48],{"class":47},[37,1083,1084],{"class":51}," \"\"\n",[37,1086,1087],{"class":39,"line":99},[37,1088,118],{"emptyLinePlaceholder":117},[37,1090,1091,1093,1095,1097],{"class":39,"line":114},[37,1092,103],{"class":102},[37,1094,81],{"class":73},[37,1096,1011],{"class":77},[37,1098,111],{"class":73},[37,1100,1101,1103,1105,1107,1109,1111],{"class":39,"line":121},[37,1102,103],{"class":102},[37,1104,81],{"class":73},[37,1106,1022],{"class":102},[37,1108,81],{"class":73},[37,1110,1011],{"class":77},[37,1112,836],{"class":73},[37,1114,1115,1117,1119,1121,1123,1125],{"class":39,"line":146},[37,1116,103],{"class":102},[37,1118,81],{"class":73},[37,1120,1037],{"class":348},[37,1122,81],{"class":73},[37,1124,1011],{"class":77},[37,1126,836],{"class":73},[37,1128,1129,1131,1133,1135],{"class":39,"line":843},[37,1130,103],{"class":102},[37,1132,81],{"class":73},[37,1134,262],{"class":77},[37,1136,111],{"class":73},[37,1138,1139],{"class":39,"line":857},[37,1140,118],{"emptyLinePlaceholder":117},[37,1142,1144,1146,1148,1150,1152,1154,1156,1158],{"class":39,"line":1143},9,[37,1145,65],{"class":43},[37,1147,48],{"class":47},[37,1149,70],{"class":43},[37,1151,74],{"class":73},[37,1153,78],{"class":77},[37,1155,81],{"class":73},[37,1157,1011],{"class":77},[37,1159,111],{"class":73},[14,1161,1162],{},"Output before the error:",[28,1164,1166],{"className":30,"code":1165,"language":32,"meta":33,"style":33},"''\n\u003Cclass 'str'>\na-b-c\n",[18,1167,1168,1174,1193],{"__ignoreMap":33},[37,1169,1170],{"class":39,"line":40},[37,1171,1173],{"class":1172},"s2W-s","''\n",[37,1175,1176,1179,1183,1185,1188,1190],{"class":39,"line":62},[37,1177,1178],{"class":47},"\u003C",[37,1180,1182],{"class":1181},"sbsja","class",[37,1184,181],{"class":51},[37,1186,1187],{"class":55},"str",[37,1189,171],{"class":51},[37,1191,1192],{"class":47},">\n",[37,1194,1195,1197,1200,1202,1204],{"class":39,"line":99},[37,1196,278],{"class":43},[37,1198,1199],{"class":47},"-",[37,1201,925],{"class":43},[37,1203,1199],{"class":47},[37,1205,1206],{"class":43},"c\n",[14,1208,1209,1212],{},[18,1210,1211],{},"repr(separator)"," is especially helpful because it makes the empty string easier to see.",[23,1214,1216],{"id":1215},"related-errors-and-confusion","Related errors and confusion",[14,1218,1219],{},"This error is different from other common string problems.",[373,1221,1222,1236,1243],{},[376,1223,1224,1225,1228,1229,1235],{},"It is ",[736,1226,1227],{},"not"," ",[278,1230,1232],{"href":1231},"\u002Ferrors\u002Fvalueerror-substring-not-found-fix\u002F",[18,1233,1234],{},"ValueError: substring not found",", which happens in different string operations",[376,1237,1238,1239,1242],{},"It is also different from a ",[18,1240,1241],{},"TypeError",", which happens when you pass the wrong data type",[376,1244,1245,1246,1248,1249],{},"Beginners often confuse ",[18,1247,361],{}," with ",[18,1250,609],{},[14,1252,1253,1254,74],{},"If you want a broader overview of this kind of error, see ",[278,1255,1257],{"href":1256},"\u002Ferrors\u002Fvalueerror-in-python-causes-and-fixes\u002F","ValueError in Python: causes and fixes",[23,1259,1261],{"id":1260},"common-mistakes","Common mistakes",[14,1263,1264],{},"These are the most common causes of this error:",[373,1266,1267,1274,1279,1285],{},[376,1268,1269,1270,1273],{},"Using ",[18,1271,1272],{},"text.split(\"\")"," directly",[376,1275,1276,1277],{},"Passing a variable that contains an empty string into ",[18,1278,235],{},[376,1280,1281,1282,1284],{},"Expecting ",[18,1283,361],{}," to return individual characters",[376,1286,1287,1288],{},"Building the separator dynamically and ending up with ",[18,1289,271],{},[14,1291,1292],{},"Example with a variable:",[28,1294,1296],{"className":30,"code":1295,"language":32,"meta":33,"style":33},"text = \"apple|banana|orange\"\nseparator = \"\"\n\nparts = text.split(separator)  # causes ValueError\nprint(parts)\n",[18,1297,1298,1311,1319,1323,1344],{"__ignoreMap":33},[37,1299,1300,1302,1304,1306,1309],{"class":39,"line":40},[37,1301,44],{"class":43},[37,1303,48],{"class":47},[37,1305,52],{"class":51},[37,1307,1308],{"class":55},"apple|banana|orange",[37,1310,59],{"class":51},[37,1312,1313,1315,1317],{"class":39,"line":62},[37,1314,1079],{"class":43},[37,1316,48],{"class":47},[37,1318,1084],{"class":51},[37,1320,1321],{"class":39,"line":99},[37,1322,118],{"emptyLinePlaceholder":117},[37,1324,1325,1327,1329,1331,1333,1335,1337,1339,1341],{"class":39,"line":114},[37,1326,65],{"class":43},[37,1328,48],{"class":47},[37,1330,70],{"class":43},[37,1332,74],{"class":73},[37,1334,78],{"class":77},[37,1336,81],{"class":73},[37,1338,1011],{"class":77},[37,1340,92],{"class":73},[37,1342,1343],{"class":95},"  # causes ValueError\n",[37,1345,1346,1348,1350,1352],{"class":39,"line":121},[37,1347,103],{"class":102},[37,1349,81],{"class":73},[37,1351,108],{"class":77},[37,1353,111],{"class":73},[14,1355,1356,1357,1359],{},"To fix it, make sure ",[18,1358,1011],{}," is not empty:",[28,1361,1363],{"className":30,"code":1362,"language":32,"meta":33,"style":33},"text = \"apple|banana|orange\"\nseparator = \"|\"\n\nparts = text.split(separator)\nprint(parts)\n",[18,1364,1365,1377,1390,1394,1412],{"__ignoreMap":33},[37,1366,1367,1369,1371,1373,1375],{"class":39,"line":40},[37,1368,44],{"class":43},[37,1370,48],{"class":47},[37,1372,52],{"class":51},[37,1374,1308],{"class":55},[37,1376,59],{"class":51},[37,1378,1379,1381,1383,1385,1388],{"class":39,"line":62},[37,1380,1079],{"class":43},[37,1382,48],{"class":47},[37,1384,52],{"class":51},[37,1386,1387],{"class":55},"|",[37,1389,59],{"class":51},[37,1391,1392],{"class":39,"line":99},[37,1393,118],{"emptyLinePlaceholder":117},[37,1395,1396,1398,1400,1402,1404,1406,1408,1410],{"class":39,"line":114},[37,1397,65],{"class":43},[37,1399,48],{"class":47},[37,1401,70],{"class":43},[37,1403,74],{"class":73},[37,1405,78],{"class":77},[37,1407,81],{"class":73},[37,1409,1011],{"class":77},[37,1411,111],{"class":73},[37,1413,1414,1416,1418,1420],{"class":39,"line":121},[37,1415,103],{"class":102},[37,1417,81],{"class":73},[37,1419,108],{"class":77},[37,1421,111],{"class":73},[14,1423,158],{},[28,1425,1427],{"className":30,"code":1426,"language":32,"meta":33,"style":33},"['apple', 'banana', 'orange']\n",[18,1428,1429],{"__ignoreMap":33},[37,1430,1431,1433,1435,1437,1439,1441,1443,1445,1447,1449,1451,1453,1455],{"class":39,"line":40},[37,1432,168],{"class":73},[37,1434,171],{"class":51},[37,1436,174],{"class":55},[37,1438,171],{"class":51},[37,1440,87],{"class":73},[37,1442,181],{"class":51},[37,1444,184],{"class":55},[37,1446,171],{"class":51},[37,1448,87],{"class":73},[37,1450,181],{"class":51},[37,1452,193],{"class":55},[37,1454,171],{"class":51},[37,1456,198],{"class":73},[23,1458,1460],{"id":1459},"faq","FAQ",[404,1462,1464,1465,1467],{"id":1463},"why-does-split-fail-in-python","Why does ",[18,1466,361],{}," fail in Python?",[14,1469,1470],{},"Because Python does not allow an empty string as a separator. The separator must contain at least one character.",[404,1472,1474],{"id":1473},"how-do-i-split-a-string-into-characters","How do I split a string into characters?",[14,1476,506,1477,1479],{},[18,1478,609],{},". That returns each character as a separate item.",[404,1481,1483],{"id":1482},"how-do-i-split-by-spaces","How do I split by spaces?",[14,1485,506,1486,1488],{},[18,1487,235],{}," with no argument. It splits on whitespace.",[404,1490,1492],{"id":1491},"can-i-use-a-variable-as-the-separator","Can I use a variable as the separator?",[14,1494,1495],{},"Yes, but make sure the variable is not an empty string.",[23,1497,1499],{"id":1498},"see-also","See also",[373,1501,1502,1510,1515,1521,1526],{},[376,1503,1504],{},[278,1505,1506,1507,1509],{"href":280},"Python string ",[18,1508,235],{}," method",[376,1511,1512],{},[278,1513,1514],{"href":602},"How to split a string in Python",[376,1516,1517],{},[278,1518,1520],{"href":1519},"\u002Fhow-to\u002Fhow-to-check-if-a-string-contains-a-substring-in-python\u002F","How to check if a string contains a substring in Python",[376,1522,1523],{},[278,1524,1525],{"href":1231},"ValueError: substring not found (Fix)",[376,1527,1528],{},[278,1529,1257],{"href":1256},[1531,1532,1533],"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 .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 .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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 pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s2W-s, html code.shiki .s2W-s{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":33,"searchDepth":62,"depth":62,"links":1535},[1536,1537,1538,1539,1540,1547,1548,1549,1550,1551,1558],{"id":25,"depth":62,"text":26},{"id":243,"depth":62,"text":244},{"id":286,"depth":62,"text":287},{"id":364,"depth":62,"text":365},{"id":401,"depth":62,"text":402,"children":1541},[1542,1543,1545],{"id":406,"depth":99,"text":407},{"id":505,"depth":99,"text":1544},"Use split() with no argument for whitespace",{"id":606,"depth":99,"text":1546},"Use list(text) for individual characters",{"id":726,"depth":62,"text":727},{"id":970,"depth":62,"text":971},{"id":1215,"depth":62,"text":1216},{"id":1260,"depth":62,"text":1261},{"id":1459,"depth":62,"text":1460,"children":1552},[1553,1555,1556,1557],{"id":1463,"depth":99,"text":1554},"Why does split(\"\") fail in Python?",{"id":1473,"depth":99,"text":1474},{"id":1482,"depth":99,"text":1483},{"id":1491,"depth":99,"text":1492},{"id":1498,"depth":62,"text":1499},"Master valueerror empty separator fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Fvalueerror-empty-separator-fix",{"title":5,"description":1559},"errors\u002Fvalueerror-empty-separator-fix","ht3i8ylO7TO5qMc7LOPgxLkZs0S-msnOeUoMnA8-YGI",1777585482855]