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