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