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