[{"data":1,"prerenderedAt":1325},["ShallowReactive",2],{"doc-\u002Fhow-to\u002Fhow-to-create-a-simple-function-in-python":3},{"id":4,"title":5,"body":6,"description":1318,"extension":1319,"meta":1320,"navigation":86,"path":1321,"seo":1322,"stem":1323,"__hash__":1324},"content\u002Fhow-to\u002Fhow-to-create-a-simple-function-in-python.md","How to Create a Simple Function in Python",{"type":7,"value":8,"toc":1292},"minimark",[9,13,17,26,31,98,104,108,124,128,131,137,157,160,185,188,192,195,231,234,244,247,261,264,277,280,307,310,314,317,353,356,384,387,447,450,493,502,514,518,521,524,535,538,555,558,575,585,589,592,595,643,646,698,700,718,721,732,736,739,744,747,774,777,780,806,818,822,824,851,854,856,882,891,897,903,939,942,978,982,985,988,1025,1028,1064,1068,1071,1097,1100,1103,1131,1134,1149,1166,1173,1177,1180,1183,1204,1208,1212,1215,1219,1224,1228,1231,1235,1238,1242,1250,1254,1288],[10,11,5],"h1",{"id":12},"how-to-create-a-simple-function-in-python",[14,15,16],"p",{},"A Python function lets you group code into a reusable block. This page shows the simplest working pattern first: define a function, then call it.",[14,18,19,20,25],{},"You will also learn how to avoid common beginner mistakes like missing parentheses or bad indentation. Once this basic pattern makes sense, it becomes much easier to learn ",[21,22,24],"a",{"href":23},"\u002Flearn\u002Fpython-functions-explained","Python functions explained",", parameters, and return values.",[27,28,30],"h2",{"id":29},"quick-answer","Quick answer",[32,33,38],"pre",{"className":34,"code":35,"language":36,"meta":37,"style":37},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","def say_hello():\n    print(\"Hello\")\n\nsay_hello()\n","python","",[39,40,41,58,81,88],"code",{"__ignoreMap":37},[42,43,46,50,54],"span",{"class":44,"line":45},"line",1,[42,47,49],{"class":48},"sbsja","def",[42,51,53],{"class":52},"sGLFI"," say_hello",[42,55,57],{"class":56},"sP7_E","():\n",[42,59,61,65,68,72,76,78],{"class":44,"line":60},2,[42,62,64],{"class":63},"sptTA","    print",[42,66,67],{"class":56},"(",[42,69,71],{"class":70},"sjJ54","\"",[42,73,75],{"class":74},"s_sjI","Hello",[42,77,71],{"class":70},[42,79,80],{"class":56},")\n",[42,82,84],{"class":44,"line":83},3,[42,85,87],{"emptyLinePlaceholder":86},true,"\n",[42,89,91,95],{"class":44,"line":90},4,[42,92,94],{"class":93},"slqww","say_hello",[42,96,97],{"class":56},"()\n",[14,99,100,101,103],{},"Use ",[39,102,49],{}," to create the function, indent the code inside it, then call the function by writing its name with parentheses.",[27,105,107],{"id":106},"what-this-page-helps-you-do","What this page helps you do",[109,110,111,115,118,121],"ul",{},[112,113,114],"li",{},"Create your first Python function",[112,116,117],{},"Understand the basic function pattern",[112,119,120],{},"Run the function by calling it",[112,122,123],{},"Avoid beginner mistakes like missing parentheses or bad indentation",[27,125,127],{"id":126},"start-with-the-basic-function-structure","Start with the basic function structure",[14,129,130],{},"A function is a reusable block of code.",[14,132,133,134,136],{},"In Python, you create a function with the ",[39,135,49],{}," keyword:",[32,138,140],{"className":34,"code":139,"language":36,"meta":37,"style":37},"def function_name():\n    # code goes here\n",[39,141,142,151],{"__ignoreMap":37},[42,143,144,146,149],{"class":44,"line":45},[42,145,49],{"class":48},[42,147,148],{"class":52}," function_name",[42,150,57],{"class":56},[42,152,153],{"class":44,"line":60},[42,154,156],{"class":155},"sutJx","    # code goes here\n",[14,158,159],{},"This pattern has four important parts:",[109,161,162,167,173,179],{},[112,163,164,166],{},[39,165,49],{}," starts the function definition",[112,168,169,172],{},[39,170,171],{},"function_name"," is the name you choose",[112,174,175,178],{},[39,176,177],{},"()"," means the function takes no inputs for now",[112,180,181,184],{},[39,182,183],{},":"," starts the function body",[14,186,187],{},"The code inside the function must be indented.",[27,189,191],{"id":190},"create-and-call-a-simple-function","Create and call a simple function",[14,193,194],{},"Here is a simple function that prints a message:",[32,196,197],{"className":34,"code":35,"language":36,"meta":37,"style":37},[39,198,199,207,221,225],{"__ignoreMap":37},[42,200,201,203,205],{"class":44,"line":45},[42,202,49],{"class":48},[42,204,53],{"class":52},[42,206,57],{"class":56},[42,208,209,211,213,215,217,219],{"class":44,"line":60},[42,210,64],{"class":63},[42,212,67],{"class":56},[42,214,71],{"class":70},[42,216,75],{"class":74},[42,218,71],{"class":70},[42,220,80],{"class":56},[42,222,223],{"class":44,"line":83},[42,224,87],{"emptyLinePlaceholder":86},[42,226,227,229],{"class":44,"line":90},[42,228,94],{"class":93},[42,230,97],{"class":56},[14,232,233],{},"Expected output:",[32,235,237],{"className":34,"code":236,"language":36,"meta":37,"style":37},"Hello\n",[39,238,239],{"__ignoreMap":37},[42,240,241],{"class":44,"line":45},[42,242,236],{"class":243},"su5hD",[14,245,246],{},"This example does two things:",[248,249,250,255],"ol",{},[112,251,252,253],{},"It defines the function ",[39,254,94],{},[112,256,257,258],{},"It calls the function with ",[39,259,260],{},"say_hello()",[14,262,263],{},"A very important rule for beginners:",[109,265,266,274],{},[112,267,268,269,273],{},"Defining a function does ",[270,271,272],"strong",{},"not"," run it",[112,275,276],{},"Nothing happens until you call the function",[14,278,279],{},"If you only write this:",[32,281,283],{"className":34,"code":282,"language":36,"meta":37,"style":37},"def say_hello():\n    print(\"Hello\")\n",[39,284,285,293],{"__ignoreMap":37},[42,286,287,289,291],{"class":44,"line":45},[42,288,49],{"class":48},[42,290,53],{"class":52},[42,292,57],{"class":56},[42,294,295,297,299,301,303,305],{"class":44,"line":60},[42,296,64],{"class":63},[42,298,67],{"class":56},[42,300,71],{"class":70},[42,302,75],{"class":74},[42,304,71],{"class":70},[42,306,80],{"class":56},[14,308,309],{},"you will see no output, because the function was created but never called.",[27,311,313],{"id":312},"understand-each-line","Understand each line",[14,315,316],{},"Look at the same example again:",[32,318,319],{"className":34,"code":35,"language":36,"meta":37,"style":37},[39,320,321,329,343,347],{"__ignoreMap":37},[42,322,323,325,327],{"class":44,"line":45},[42,324,49],{"class":48},[42,326,53],{"class":52},[42,328,57],{"class":56},[42,330,331,333,335,337,339,341],{"class":44,"line":60},[42,332,64],{"class":63},[42,334,67],{"class":56},[42,336,71],{"class":70},[42,338,75],{"class":74},[42,340,71],{"class":70},[42,342,80],{"class":56},[42,344,345],{"class":44,"line":83},[42,346,87],{"emptyLinePlaceholder":86},[42,348,349,351],{"class":44,"line":90},[42,350,94],{"class":93},[42,352,97],{"class":56},[14,354,355],{},"Here is what each line does:",[109,357,358,363,368,373,379],{},[112,359,360,166],{},[39,361,362],{},"def say_hello():",[112,364,365,367],{},[39,366,94],{}," is the function name",[112,369,370,372],{},[39,371,183],{}," tells Python that the function body starts next",[112,374,375,378],{},[39,376,377],{},"print(\"Hello\")"," is inside the function because it is indented",[112,380,381,383],{},[39,382,260],{}," runs the code inside the function",[14,385,386],{},"You can test that the function exists by printing its name without calling it:",[32,388,390],{"className":34,"code":389,"language":36,"meta":37,"style":37},"def say_hello():\n    print(\"Hello\")\n\nprint(say_hello)\nprint(type(say_hello))\n",[39,391,392,400,414,418,429],{"__ignoreMap":37},[42,393,394,396,398],{"class":44,"line":45},[42,395,49],{"class":48},[42,397,53],{"class":52},[42,399,57],{"class":56},[42,401,402,404,406,408,410,412],{"class":44,"line":60},[42,403,64],{"class":63},[42,405,67],{"class":56},[42,407,71],{"class":70},[42,409,75],{"class":74},[42,411,71],{"class":70},[42,413,80],{"class":56},[42,415,416],{"class":44,"line":83},[42,417,87],{"emptyLinePlaceholder":86},[42,419,420,423,425,427],{"class":44,"line":90},[42,421,422],{"class":63},"print",[42,424,67],{"class":56},[42,426,94],{"class":93},[42,428,80],{"class":56},[42,430,432,434,436,440,442,444],{"class":44,"line":431},5,[42,433,422],{"class":63},[42,435,67],{"class":56},[42,437,439],{"class":438},"sZMiF","type",[42,441,67],{"class":56},[42,443,94],{"class":93},[42,445,446],{"class":56},"))\n",[14,448,449],{},"You will see that Python treats the function as an object:",[32,451,453],{"className":34,"code":452,"language":36,"meta":37,"style":37},"\u003Cfunction say_hello at 0x...>\n\u003Cclass 'function'>\n",[39,454,455,475],{"__ignoreMap":37},[42,456,457,461,464,468,472],{"class":44,"line":45},[42,458,460],{"class":459},"smGrS","\u003C",[42,462,463],{"class":243},"function say_hello at ",[42,465,467],{"class":466},"srjyR","0x",[42,469,471],{"class":470},"s_hVV","...",[42,473,474],{"class":459},">\n",[42,476,477,479,482,485,488,491],{"class":44,"line":60},[42,478,460],{"class":459},[42,480,481],{"class":48},"class",[42,483,484],{"class":70}," '",[42,486,487],{"class":74},"function",[42,489,490],{"class":70},"'",[42,492,474],{"class":459},[14,494,495,496,498,499,501],{},"This is why ",[39,497,94],{}," and ",[39,500,260],{}," are different:",[109,503,504,509],{},[112,505,506,508],{},[39,507,94],{}," refers to the function",[112,510,511,513],{},[39,512,260],{}," calls the function",[27,515,517],{"id":516},"choose-a-good-function-name","Choose a good function name",[14,519,520],{},"A good function name should describe what the function does.",[14,522,523],{},"Use:",[109,525,526,529,532],{},[112,527,528],{},"lowercase letters",[112,530,531],{},"underscores between words",[112,533,534],{},"action-based names",[14,536,537],{},"Good examples:",[109,539,540,545,550],{},[112,541,542],{},[39,543,544],{},"print_name",[112,546,547],{},[39,548,549],{},"show_menu",[112,551,552],{},[39,553,554],{},"get_total",[14,556,557],{},"Avoid vague names like:",[109,559,560,565,570],{},[112,561,562],{},[39,563,564],{},"thing",[112,566,567],{},[39,568,569],{},"stuff",[112,571,572],{},[39,573,574],{},"do_stuff",[14,576,577,578,581,582,584],{},"Also avoid names that conflict with Python built-ins, such as ",[39,579,580],{},"list"," or ",[39,583,422],{},". Reusing built-in names can cause confusing bugs later.",[27,586,588],{"id":587},"add-a-second-simple-example","Add a second simple example",[14,590,591],{},"Functions are useful because you can reuse them.",[14,593,594],{},"Without a function, you might repeat the same line many times:",[32,596,598],{"className":34,"code":597,"language":36,"meta":37,"style":37},"print(\"Welcome!\")\nprint(\"Welcome!\")\nprint(\"Welcome!\")\n",[39,599,600,615,629],{"__ignoreMap":37},[42,601,602,604,606,608,611,613],{"class":44,"line":45},[42,603,422],{"class":63},[42,605,67],{"class":56},[42,607,71],{"class":70},[42,609,610],{"class":74},"Welcome!",[42,612,71],{"class":70},[42,614,80],{"class":56},[42,616,617,619,621,623,625,627],{"class":44,"line":60},[42,618,422],{"class":63},[42,620,67],{"class":56},[42,622,71],{"class":70},[42,624,610],{"class":74},[42,626,71],{"class":70},[42,628,80],{"class":56},[42,630,631,633,635,637,639,641],{"class":44,"line":83},[42,632,422],{"class":63},[42,634,67],{"class":56},[42,636,71],{"class":70},[42,638,610],{"class":74},[42,640,71],{"class":70},[42,642,80],{"class":56},[14,644,645],{},"With a function, you write the code once and call it whenever you need it:",[32,647,649],{"className":34,"code":648,"language":36,"meta":37,"style":37},"def show_welcome():\n    print(\"Welcome!\")\n\nshow_welcome()\nshow_welcome()\nshow_welcome()\n",[39,650,651,660,674,678,685,691],{"__ignoreMap":37},[42,652,653,655,658],{"class":44,"line":45},[42,654,49],{"class":48},[42,656,657],{"class":52}," show_welcome",[42,659,57],{"class":56},[42,661,662,664,666,668,670,672],{"class":44,"line":60},[42,663,64],{"class":63},[42,665,67],{"class":56},[42,667,71],{"class":70},[42,669,610],{"class":74},[42,671,71],{"class":70},[42,673,80],{"class":56},[42,675,676],{"class":44,"line":83},[42,677,87],{"emptyLinePlaceholder":86},[42,679,680,683],{"class":44,"line":90},[42,681,682],{"class":93},"show_welcome",[42,684,97],{"class":56},[42,686,687,689],{"class":44,"line":431},[42,688,682],{"class":93},[42,690,97],{"class":56},[42,692,694,696],{"class":44,"line":693},6,[42,695,682],{"class":93},[42,697,97],{"class":56},[14,699,233],{},[32,701,703],{"className":34,"code":702,"language":36,"meta":37,"style":37},"Welcome!\nWelcome!\nWelcome!\n",[39,704,705,710,714],{"__ignoreMap":37},[42,706,707],{"class":44,"line":45},[42,708,709],{"class":243},"Welcome!\n",[42,711,712],{"class":44,"line":60},[42,713,709],{"class":243},[42,715,716],{"class":44,"line":83},[42,717,709],{"class":243},[14,719,720],{},"This is one of the main reasons functions are helpful:",[109,722,723,726,729],{},[112,724,725],{},"less repeated code",[112,727,728],{},"easier to update later",[112,730,731],{},"clearer program structure",[27,733,735],{"id":734},"common-beginner-mistakes","Common beginner mistakes",[14,737,738],{},"Here are some common problems when creating a simple function.",[740,741,743],"h3",{"id":742},"forgetting-the-colon","Forgetting the colon",[14,745,746],{},"This is wrong:",[32,748,750],{"className":34,"code":749,"language":36,"meta":37,"style":37},"def say_hello()\n    print(\"Hello\")\n",[39,751,752,760],{"__ignoreMap":37},[42,753,754,756,758],{"class":44,"line":45},[42,755,49],{"class":48},[42,757,53],{"class":52},[42,759,97],{"class":56},[42,761,762,764,766,768,770,772],{"class":44,"line":60},[42,763,64],{"class":63},[42,765,67],{"class":56},[42,767,71],{"class":70},[42,769,75],{"class":74},[42,771,71],{"class":70},[42,773,80],{"class":56},[14,775,776],{},"Python expects a colon after the function header.",[14,778,779],{},"Correct version:",[32,781,782],{"className":34,"code":282,"language":36,"meta":37,"style":37},[39,783,784,792],{"__ignoreMap":37},[42,785,786,788,790],{"class":44,"line":45},[42,787,49],{"class":48},[42,789,53],{"class":52},[42,791,57],{"class":56},[42,793,794,796,798,800,802,804],{"class":44,"line":60},[42,795,64],{"class":63},[42,797,67],{"class":56},[42,799,71],{"class":70},[42,801,75],{"class":74},[42,803,71],{"class":70},[42,805,80],{"class":56},[14,807,808,809,817],{},"If you get this wrong, see ",[21,810,812,813,816],{"href":811},"\u002Ferrors\u002Fsyntaxerror-missing-colon-fix","how to fix ",[39,814,815],{},"SyntaxError"," from a missing colon",".",[740,819,821],{"id":820},"forgetting-to-indent-the-function-body","Forgetting to indent the function body",[14,823,746],{},[32,825,827],{"className":34,"code":826,"language":36,"meta":37,"style":37},"def say_hello():\nprint(\"Hello\")\n",[39,828,829,837],{"__ignoreMap":37},[42,830,831,833,835],{"class":44,"line":45},[42,832,49],{"class":48},[42,834,53],{"class":52},[42,836,57],{"class":56},[42,838,839,841,843,845,847,849],{"class":44,"line":60},[42,840,422],{"class":63},[42,842,67],{"class":56},[42,844,71],{"class":70},[42,846,75],{"class":74},[42,848,71],{"class":70},[42,850,80],{"class":56},[14,852,853],{},"The body of the function must be indented.",[14,855,779],{},[32,857,858],{"className":34,"code":282,"language":36,"meta":37,"style":37},[39,859,860,868],{"__ignoreMap":37},[42,861,862,864,866],{"class":44,"line":45},[42,863,49],{"class":48},[42,865,53],{"class":52},[42,867,57],{"class":56},[42,869,870,872,874,876,878,880],{"class":44,"line":60},[42,871,64],{"class":63},[42,873,67],{"class":56},[42,875,71],{"class":70},[42,877,75],{"class":74},[42,879,71],{"class":70},[42,881,80],{"class":56},[14,883,884,885,817],{},"If Python says it expected an indented block, read ",[21,886,812,888],{"href":887},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix",[39,889,890],{},"IndentationError: expected an indented block",[740,892,894,895],{"id":893},"using-the-function-name-without","Using the function name without ",[39,896,177],{},[14,898,899,900,902],{},"This does ",[270,901,272],{}," call the function:",[32,904,906],{"className":34,"code":905,"language":36,"meta":37,"style":37},"def say_hello():\n    print(\"Hello\")\n\nsay_hello\n",[39,907,908,916,930,934],{"__ignoreMap":37},[42,909,910,912,914],{"class":44,"line":45},[42,911,49],{"class":48},[42,913,53],{"class":52},[42,915,57],{"class":56},[42,917,918,920,922,924,926,928],{"class":44,"line":60},[42,919,64],{"class":63},[42,921,67],{"class":56},[42,923,71],{"class":70},[42,925,75],{"class":74},[42,927,71],{"class":70},[42,929,80],{"class":56},[42,931,932],{"class":44,"line":83},[42,933,87],{"emptyLinePlaceholder":86},[42,935,936],{"class":44,"line":90},[42,937,938],{"class":243},"say_hello\n",[14,940,941],{},"To run the function, you must add parentheses:",[32,943,944],{"className":34,"code":35,"language":36,"meta":37,"style":37},[39,945,946,954,968,972],{"__ignoreMap":37},[42,947,948,950,952],{"class":44,"line":45},[42,949,49],{"class":48},[42,951,53],{"class":52},[42,953,57],{"class":56},[42,955,956,958,960,962,964,966],{"class":44,"line":60},[42,957,64],{"class":63},[42,959,67],{"class":56},[42,961,71],{"class":70},[42,963,75],{"class":74},[42,965,71],{"class":70},[42,967,80],{"class":56},[42,969,970],{"class":44,"line":83},[42,971,87],{"emptyLinePlaceholder":86},[42,973,974,976],{"class":44,"line":90},[42,975,94],{"class":93},[42,977,97],{"class":56},[740,979,981],{"id":980},"calling-the-function-before-it-is-defined","Calling the function before it is defined",[14,983,984],{},"In a Python file, the function usually needs to be defined before you call it.",[14,986,987],{},"Wrong order:",[32,989,991],{"className":34,"code":990,"language":36,"meta":37,"style":37},"say_hello()\n\ndef say_hello():\n    print(\"Hello\")\n",[39,992,993,999,1003,1011],{"__ignoreMap":37},[42,994,995,997],{"class":44,"line":45},[42,996,94],{"class":93},[42,998,97],{"class":56},[42,1000,1001],{"class":44,"line":60},[42,1002,87],{"emptyLinePlaceholder":86},[42,1004,1005,1007,1009],{"class":44,"line":83},[42,1006,49],{"class":48},[42,1008,53],{"class":52},[42,1010,57],{"class":56},[42,1012,1013,1015,1017,1019,1021,1023],{"class":44,"line":90},[42,1014,64],{"class":63},[42,1016,67],{"class":56},[42,1018,71],{"class":70},[42,1020,75],{"class":74},[42,1022,71],{"class":70},[42,1024,80],{"class":56},[14,1026,1027],{},"Correct order:",[32,1029,1030],{"className":34,"code":35,"language":36,"meta":37,"style":37},[39,1031,1032,1040,1054,1058],{"__ignoreMap":37},[42,1033,1034,1036,1038],{"class":44,"line":45},[42,1035,49],{"class":48},[42,1037,53],{"class":52},[42,1039,57],{"class":56},[42,1041,1042,1044,1046,1048,1050,1052],{"class":44,"line":60},[42,1043,64],{"class":63},[42,1045,67],{"class":56},[42,1047,71],{"class":70},[42,1049,75],{"class":74},[42,1051,71],{"class":70},[42,1053,80],{"class":56},[42,1055,1056],{"class":44,"line":83},[42,1057,87],{"emptyLinePlaceholder":86},[42,1059,1060,1062],{"class":44,"line":90},[42,1061,94],{"class":93},[42,1063,97],{"class":56},[740,1065,1067],{"id":1066},"expecting-a-printed-value-to-be-returned","Expecting a printed value to be returned",[14,1069,1070],{},"This function prints a message:",[32,1072,1073],{"className":34,"code":282,"language":36,"meta":37,"style":37},[39,1074,1075,1083],{"__ignoreMap":37},[42,1076,1077,1079,1081],{"class":44,"line":45},[42,1078,49],{"class":48},[42,1080,53],{"class":52},[42,1082,57],{"class":56},[42,1084,1085,1087,1089,1091,1093,1095],{"class":44,"line":60},[42,1086,64],{"class":63},[42,1088,67],{"class":56},[42,1090,71],{"class":70},[42,1092,75],{"class":74},[42,1094,71],{"class":70},[42,1096,80],{"class":56},[14,1098,1099],{},"But it does not return a value.",[14,1101,1102],{},"That means this:",[32,1104,1106],{"className":34,"code":1105,"language":36,"meta":37,"style":37},"result = say_hello()\nprint(result)\n",[39,1107,1108,1120],{"__ignoreMap":37},[42,1109,1110,1113,1116,1118],{"class":44,"line":45},[42,1111,1112],{"class":243},"result ",[42,1114,1115],{"class":459},"=",[42,1117,53],{"class":93},[42,1119,97],{"class":56},[42,1121,1122,1124,1126,1129],{"class":44,"line":60},[42,1123,422],{"class":63},[42,1125,67],{"class":56},[42,1127,1128],{"class":93},"result",[42,1130,80],{"class":56},[14,1132,1133],{},"will output:",[32,1135,1137],{"className":34,"code":1136,"language":36,"meta":37,"style":37},"Hello\nNone\n",[39,1138,1139,1143],{"__ignoreMap":37},[42,1140,1141],{"class":44,"line":45},[42,1142,236],{"class":243},[42,1144,1145],{"class":44,"line":60},[42,1146,1148],{"class":1147},"s39Yj","None\n",[109,1150,1151,1156],{},[112,1152,1153,1155],{},[39,1154,377],{}," shows text on the screen",[112,1157,1158,1159,1162,1163],{},"the function returns ",[39,1160,1161],{},"None"," because there is no ",[39,1164,1165],{},"return",[14,1167,1168,1169,817],{},"If this part feels confusing, the next step is learning ",[21,1170,1172],{"href":1171},"\u002Flearn\u002Freturn-values-in-python-functions","return values in Python functions",[27,1174,1176],{"id":1175},"what-to-learn-next","What to learn next",[14,1178,1179],{},"Once you can create and call a simple function, the next step is making functions more useful.",[14,1181,1182],{},"You can learn how to:",[109,1184,1185,1192,1197],{},[112,1186,1187,1188],{},"pass inputs with ",[21,1189,1191],{"href":1190},"\u002Flearn\u002Ffunction-parameters-and-arguments-in-python","function parameters and arguments in Python",[112,1193,1194,1195],{},"send a result back with ",[21,1196,1172],{"href":1171},[112,1198,1199,1200],{},"make inputs optional with ",[21,1201,1203],{"href":1202},"\u002Fhow-to\u002Fhow-to-use-default-arguments-in-python\u002F","default arguments in Python",[27,1205,1207],{"id":1206},"faq","FAQ",[740,1209,1211],{"id":1210},"what-is-a-function-in-python","What is a function in Python?",[14,1213,1214],{},"A function is a reusable block of code that runs when you call it.",[740,1216,1218],{"id":1217},"how-do-i-create-a-function-in-python","How do I create a function in Python?",[14,1220,100,1221,1223],{},[39,1222,49],{},", write the function name, add parentheses and a colon, then indent the code inside it.",[740,1225,1227],{"id":1226},"why-is-my-function-not-running","Why is my function not running?",[14,1229,1230],{},"It may be defined correctly but not called. Write the function name followed by parentheses to run it.",[740,1232,1234],{"id":1233},"do-functions-always-need-parameters","Do functions always need parameters?",[14,1236,1237],{},"No. A simple function can work without parameters.",[740,1239,1241],{"id":1240},"what-is-the-difference-between-print-and-return","What is the difference between print and return?",[14,1243,1244,1246,1247,1249],{},[39,1245,422],{}," shows output on the screen. ",[39,1248,1165],{}," sends a value back from the function.",[27,1251,1253],{"id":1252},"see-also","See also",[109,1255,1256,1260,1265,1270,1275,1282],{},[112,1257,1258],{},[21,1259,24],{"href":23},[112,1261,1262],{},[21,1263,1264],{"href":1190},"Function parameters and arguments in Python",[112,1266,1267],{},[21,1268,1269],{"href":1171},"Return values in Python functions",[112,1271,1272],{},[21,1273,1274],{"href":1202},"How to use default arguments in Python",[112,1276,1277],{},[21,1278,1279,1280],{"href":887},"Fix ",[39,1281,890],{},[112,1283,1284],{},[21,1285,1279,1286,816],{"href":811},[39,1287,815],{},[1289,1290,1291],"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 .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--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 .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 .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 .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .srjyR, html code.shiki .srjyR{--shiki-light:#90A4AE;--shiki-light-font-style:inherit;--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":37,"searchDepth":60,"depth":60,"links":1293},[1294,1295,1296,1297,1298,1299,1300,1301,1309,1310,1317],{"id":29,"depth":60,"text":30},{"id":106,"depth":60,"text":107},{"id":126,"depth":60,"text":127},{"id":190,"depth":60,"text":191},{"id":312,"depth":60,"text":313},{"id":516,"depth":60,"text":517},{"id":587,"depth":60,"text":588},{"id":734,"depth":60,"text":735,"children":1302},[1303,1304,1305,1307,1308],{"id":742,"depth":83,"text":743},{"id":820,"depth":83,"text":821},{"id":893,"depth":83,"text":1306},"Using the function name without ()",{"id":980,"depth":83,"text":981},{"id":1066,"depth":83,"text":1067},{"id":1175,"depth":60,"text":1176},{"id":1206,"depth":60,"text":1207,"children":1311},[1312,1313,1314,1315,1316],{"id":1210,"depth":83,"text":1211},{"id":1217,"depth":83,"text":1218},{"id":1226,"depth":83,"text":1227},{"id":1233,"depth":83,"text":1234},{"id":1240,"depth":83,"text":1241},{"id":1252,"depth":60,"text":1253},"Master how to create a simple function in python in our comprehensive Python beginner guide.","md",{},"\u002Fhow-to\u002Fhow-to-create-a-simple-function-in-python",{"title":5,"description":1318},"how-to\u002Fhow-to-create-a-simple-function-in-python","lqI_R_0RCqVJuNnY6nCb9l6HtKFK5i2feQfObItSynw",1777585496413]