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