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