[{"data":1,"prerenderedAt":1924},["ShallowReactive",2],{"doc-\u002Fstandard-library\u002Fmath.pow-function-explained":3},{"id":4,"title":5,"body":6,"description":1917,"extension":1918,"meta":1919,"navigation":70,"path":1920,"seo":1921,"stem":1922,"__hash__":1923},"content\u002Fstandard-library\u002Fmath.pow-function-explained.md","math.pow() Function Explained",{"type":7,"value":8,"toc":1877},"minimark",[9,13,21,38,43,128,142,146,151,165,168,177,180,204,207,247,250,274,282,286,289,341,344,366,372,379,449,453,458,499,505,509,551,561,565,608,622,626,668,682,686,695,699,756,760,800,804,809,815,828,832,845,855,859,864,867,880,883,896,905,909,913,923,951,957,960,997,1004,1012,1015,1049,1055,1058,1105,1108,1138,1142,1145,1193,1203,1206,1228,1232,1237,1286,1289,1327,1330,1412,1416,1425,1428,1468,1471,1475,1480,1486,1511,1517,1522,1530,1566,1574,1583,1586,1688,1693,1698,1771,1777,1781,1785,1788,1792,1804,1808,1822,1826,1832,1836,1844,1848,1873],[10,11,5],"h1",{"id":12},"mathpow-function-explained",[14,15,16,20],"p",{},[17,18,19],"code",{},"math.pow()"," raises one number to the power of another.",[14,22,23,24,27,28,30,31,33,34,37],{},"It is part of Python’s ",[17,25,26],{},"math"," module, so you must import ",[17,29,26],{}," before using it. This function is useful when you are already working with other math functions, but beginners should also know that ",[17,32,19],{}," is different from the ",[17,35,36],{},"**"," operator.",[39,40,42],"h2",{"id":41},"quick-answer","Quick answer",[44,45,50],"pre",{"className":46,"code":47,"language":48,"meta":49,"style":49},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import math\n\nresult = math.pow(2, 3)\nprint(result)  # 8.0\n","python","",[17,51,52,65,72,109],{"__ignoreMap":49},[53,54,57,61],"span",{"class":55,"line":56},"line",1,[53,58,60],{"class":59},"sVHd0","import",[53,62,64],{"class":63},"su5hD"," math\n",[53,66,68],{"class":55,"line":67},2,[53,69,71],{"emptyLinePlaceholder":70},true,"\n",[53,73,75,78,82,85,89,93,96,100,103,106],{"class":55,"line":74},3,[53,76,77],{"class":63},"result ",[53,79,81],{"class":80},"smGrS","=",[53,83,84],{"class":63}," math",[53,86,88],{"class":87},"sP7_E",".",[53,90,92],{"class":91},"slqww","pow",[53,94,95],{"class":87},"(",[53,97,99],{"class":98},"srdBf","2",[53,101,102],{"class":87},",",[53,104,105],{"class":98}," 3",[53,107,108],{"class":87},")\n",[53,110,112,116,118,121,124],{"class":55,"line":111},4,[53,113,115],{"class":114},"sptTA","print",[53,117,95],{"class":87},[53,119,120],{"class":91},"result",[53,122,123],{"class":87},")",[53,125,127],{"class":126},"sutJx","  # 8.0\n",[14,129,130,133,134,137,138,141],{},[17,131,132],{},"math.pow(x, y)"," returns ",[17,135,136],{},"x"," raised to the power of ",[17,139,140],{},"y",". It always returns a float.",[39,143,145],{"id":144},"what-mathpow-does","What math.pow() does",[14,147,148,150],{},[17,149,19],{}," takes two numbers:",[152,153,154,160],"ul",{},[155,156,157,159],"li",{},[17,158,136],{},": the base number",[155,161,162,164],{},[17,163,140],{},": the exponent",[14,166,167],{},"It calculates:",[44,169,171],{"className":46,"code":170,"language":48,"meta":49,"style":49},"x raised to the power of y\n",[17,172,173],{"__ignoreMap":49},[53,174,175],{"class":55,"line":56},[53,176,170],{"class":63},[14,178,179],{},"The syntax is:",[44,181,183],{"className":46,"code":182,"language":48,"meta":49,"style":49},"math.pow(x, y)\n",[17,184,185],{"__ignoreMap":49},[53,186,187,189,191,193,195,197,199,202],{"class":55,"line":56},[53,188,26],{"class":63},[53,190,88],{"class":87},[53,192,92],{"class":91},[53,194,95],{"class":87},[53,196,136],{"class":91},[53,198,102],{"class":87},[53,200,201],{"class":91}," y",[53,203,108],{"class":87},[14,205,206],{},"Example:",[44,208,210],{"className":46,"code":209,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(2, 3))  # 8.0\n",[17,211,212,218,222],{"__ignoreMap":49},[53,213,214,216],{"class":55,"line":56},[53,215,60],{"class":59},[53,217,64],{"class":63},[53,219,220],{"class":55,"line":67},[53,221,71],{"emptyLinePlaceholder":70},[53,223,224,226,228,230,232,234,236,238,240,242,245],{"class":55,"line":74},[53,225,115],{"class":114},[53,227,95],{"class":87},[53,229,26],{"class":91},[53,231,88],{"class":87},[53,233,92],{"class":91},[53,235,95],{"class":87},[53,237,99],{"class":98},[53,239,102],{"class":87},[53,241,105],{"class":98},[53,243,244],{"class":87},"))",[53,246,127],{"class":126},[14,248,249],{},"Important points:",[152,251,252,255,261,268],{},[155,253,254],{},"It raises one number to the power of another",[155,256,257,258,260],{},"It is part of the ",[17,259,26],{}," module",[155,262,263,264,267],{},"You must write ",[17,265,266],{},"import math"," first",[155,269,270,271],{},"It returns a ",[17,272,273],{},"float",[14,275,276,277,88],{},"If you want a broader introduction to math functions, see the ",[278,279,281],"a",{"href":280},"\u002Fstandard-library\u002Fpython-math-module-overview","Python math module overview",[39,283,285],{"id":284},"basic-syntax","Basic syntax",[14,287,288],{},"The basic form looks like this:",[44,290,292],{"className":46,"code":291,"language":48,"meta":49,"style":49},"import math\n\nresult = math.pow(4, 2)\nprint(result)  # 16.0\n",[17,293,294,300,304,328],{"__ignoreMap":49},[53,295,296,298],{"class":55,"line":56},[53,297,60],{"class":59},[53,299,64],{"class":63},[53,301,302],{"class":55,"line":67},[53,303,71],{"emptyLinePlaceholder":70},[53,305,306,308,310,312,314,316,318,321,323,326],{"class":55,"line":74},[53,307,77],{"class":63},[53,309,81],{"class":80},[53,311,84],{"class":63},[53,313,88],{"class":87},[53,315,92],{"class":91},[53,317,95],{"class":87},[53,319,320],{"class":98},"4",[53,322,102],{"class":87},[53,324,325],{"class":98}," 2",[53,327,108],{"class":87},[53,329,330,332,334,336,338],{"class":55,"line":111},[53,331,115],{"class":114},[53,333,95],{"class":87},[53,335,120],{"class":91},[53,337,123],{"class":87},[53,339,340],{"class":126},"  # 16.0\n",[14,342,343],{},"Here:",[152,345,346,351,356],{},[155,347,348,350],{},[17,349,320],{}," is the base",[155,352,353,355],{},[17,354,99],{}," is the exponent",[155,357,358,359,362,363],{},"the result is ",[17,360,361],{},"16.0",", not ",[17,364,365],{},"16",[14,367,368,369,371],{},"Even when the answer looks like a whole number, ",[17,370,19],{}," still returns a float.",[14,373,374,375,378],{},"You can confirm that with ",[17,376,377],{},"type()",":",[44,380,382],{"className":46,"code":381,"language":48,"meta":49,"style":49},"import math\n\nresult = math.pow(4, 2)\nprint(result)         # 16.0\nprint(type(result))   # \u003Cclass 'float'>\n",[17,383,384,390,394,416,429],{"__ignoreMap":49},[53,385,386,388],{"class":55,"line":56},[53,387,60],{"class":59},[53,389,64],{"class":63},[53,391,392],{"class":55,"line":67},[53,393,71],{"emptyLinePlaceholder":70},[53,395,396,398,400,402,404,406,408,410,412,414],{"class":55,"line":74},[53,397,77],{"class":63},[53,399,81],{"class":80},[53,401,84],{"class":63},[53,403,88],{"class":87},[53,405,92],{"class":91},[53,407,95],{"class":87},[53,409,320],{"class":98},[53,411,102],{"class":87},[53,413,325],{"class":98},[53,415,108],{"class":87},[53,417,418,420,422,424,426],{"class":55,"line":111},[53,419,115],{"class":114},[53,421,95],{"class":87},[53,423,120],{"class":91},[53,425,123],{"class":87},[53,427,428],{"class":126},"         # 16.0\n",[53,430,432,434,436,440,442,444,446],{"class":55,"line":431},5,[53,433,115],{"class":114},[53,435,95],{"class":87},[53,437,439],{"class":438},"sZMiF","type",[53,441,95],{"class":87},[53,443,120],{"class":91},[53,445,244],{"class":87},[53,447,448],{"class":126},"   # \u003Cclass 'float'>\n",[39,450,452],{"id":451},"simple-examples","Simple examples",[454,455,457],"h3",{"id":456},"positive-exponent","Positive exponent",[44,459,461],{"className":46,"code":460,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(3, 2))  # 9.0\n",[17,462,463,469,473],{"__ignoreMap":49},[53,464,465,467],{"class":55,"line":56},[53,466,60],{"class":59},[53,468,64],{"class":63},[53,470,471],{"class":55,"line":67},[53,472,71],{"emptyLinePlaceholder":70},[53,474,475,477,479,481,483,485,487,490,492,494,496],{"class":55,"line":74},[53,476,115],{"class":114},[53,478,95],{"class":87},[53,480,26],{"class":91},[53,482,88],{"class":87},[53,484,92],{"class":91},[53,486,95],{"class":87},[53,488,489],{"class":98},"3",[53,491,102],{"class":87},[53,493,325],{"class":98},[53,495,244],{"class":87},[53,497,498],{"class":126},"  # 9.0\n",[14,500,501,502,88],{},"This means ",[17,503,504],{},"3 × 3",[454,506,508],{"id":507},"zero-exponent","Zero exponent",[44,510,512],{"className":46,"code":511,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(5, 0))  # 1.0\n",[17,513,514,520,524],{"__ignoreMap":49},[53,515,516,518],{"class":55,"line":56},[53,517,60],{"class":59},[53,519,64],{"class":63},[53,521,522],{"class":55,"line":67},[53,523,71],{"emptyLinePlaceholder":70},[53,525,526,528,530,532,534,536,538,541,543,546,548],{"class":55,"line":74},[53,527,115],{"class":114},[53,529,95],{"class":87},[53,531,26],{"class":91},[53,533,88],{"class":87},[53,535,92],{"class":91},[53,537,95],{"class":87},[53,539,540],{"class":98},"5",[53,542,102],{"class":87},[53,544,545],{"class":98}," 0",[53,547,244],{"class":87},[53,549,550],{"class":126},"  # 1.0\n",[14,552,553,554,557,558,88],{},"Any non-zero number raised to the power of ",[17,555,556],{},"0"," is ",[17,559,560],{},"1",[454,562,564],{"id":563},"negative-exponent","Negative exponent",[44,566,568],{"className":46,"code":567,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(2, -1))  # 0.5\n",[17,569,570,576,580],{"__ignoreMap":49},[53,571,572,574],{"class":55,"line":56},[53,573,60],{"class":59},[53,575,64],{"class":63},[53,577,578],{"class":55,"line":67},[53,579,71],{"emptyLinePlaceholder":70},[53,581,582,584,586,588,590,592,594,596,598,601,603,605],{"class":55,"line":74},[53,583,115],{"class":114},[53,585,95],{"class":87},[53,587,26],{"class":91},[53,589,88],{"class":87},[53,591,92],{"class":91},[53,593,95],{"class":87},[53,595,99],{"class":98},[53,597,102],{"class":87},[53,599,600],{"class":80}," -",[53,602,560],{"class":98},[53,604,244],{"class":87},[53,606,607],{"class":126},"  # 0.5\n",[14,609,610,611,614,615,618,619,88],{},"A negative exponent means reciprocal power.",[612,613],"br",{},"\nSo ",[17,616,617],{},"2^-1"," means ",[17,620,621],{},"1 \u002F 2",[454,623,625],{"id":624},"fractional-exponent","Fractional exponent",[44,627,629],{"className":46,"code":628,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(9, 0.5))  # 3.0\n",[17,630,631,637,641],{"__ignoreMap":49},[53,632,633,635],{"class":55,"line":56},[53,634,60],{"class":59},[53,636,64],{"class":63},[53,638,639],{"class":55,"line":67},[53,640,71],{"emptyLinePlaceholder":70},[53,642,643,645,647,649,651,653,655,658,660,663,665],{"class":55,"line":74},[53,644,115],{"class":114},[53,646,95],{"class":87},[53,648,26],{"class":91},[53,650,88],{"class":87},[53,652,92],{"class":91},[53,654,95],{"class":87},[53,656,657],{"class":98},"9",[53,659,102],{"class":87},[53,661,662],{"class":98}," 0.5",[53,664,244],{"class":87},[53,666,667],{"class":126},"  # 3.0\n",[14,669,670,671,674,675,681],{},"An exponent of ",[17,672,673],{},"0.5"," means square root. For square roots, ",[278,676,678],{"href":677},"\u002Fstandard-library\u002Fmath.sqrt-function-explained",[17,679,680],{},"math.sqrt()"," is often easier to read.",[39,683,685],{"id":684},"mathpow-vs","math.pow() vs **",[14,687,688,689,691,692,694],{},"Beginners often ask whether ",[17,690,19],{}," and ",[17,693,36],{}," are the same. They both perform exponentiation, but they do not behave exactly the same way.",[454,696,698],{"id":697},"example-comparison","Example comparison",[44,700,702],{"className":46,"code":701,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(2, 3))  # 8.0\nprint(2 ** 3)          # 8\n",[17,703,704,710,714,738],{"__ignoreMap":49},[53,705,706,708],{"class":55,"line":56},[53,707,60],{"class":59},[53,709,64],{"class":63},[53,711,712],{"class":55,"line":67},[53,713,71],{"emptyLinePlaceholder":70},[53,715,716,718,720,722,724,726,728,730,732,734,736],{"class":55,"line":74},[53,717,115],{"class":114},[53,719,95],{"class":87},[53,721,26],{"class":91},[53,723,88],{"class":87},[53,725,92],{"class":91},[53,727,95],{"class":87},[53,729,99],{"class":98},[53,731,102],{"class":87},[53,733,105],{"class":98},[53,735,244],{"class":87},[53,737,127],{"class":126},[53,739,740,742,744,746,749,751,753],{"class":55,"line":111},[53,741,115],{"class":114},[53,743,95],{"class":87},[53,745,99],{"class":98},[53,747,748],{"class":80}," **",[53,750,105],{"class":98},[53,752,123],{"class":87},[53,754,755],{"class":126},"          # 8\n",[454,757,759],{"id":758},"main-differences","Main differences",[152,761,762,770,778,785,790,795],{},[155,763,764,133,767],{},[17,765,766],{},"math.pow(2, 3)",[17,768,769],{},"8.0",[155,771,772,133,775],{},[17,773,774],{},"2 ** 3",[17,776,777],{},"8",[155,779,780,782,783],{},[17,781,19],{}," requires ",[17,784,266],{},[155,786,787,789],{},[17,788,36],{}," works without importing anything",[155,791,792,794],{},[17,793,19],{}," converts values to float",[155,796,797,799],{},[17,798,36],{}," follows normal Python exponent behavior",[454,801,803],{"id":802},"which-should-you-use","Which should you use?",[14,805,806,807,88],{},"In most everyday Python code, beginners will usually want ",[17,808,36],{},[14,810,811,812,814],{},"Use ",[17,813,36],{}," when:",[152,816,817,820,825],{},[155,818,819],{},"you want simple exponentiation",[155,821,822,823],{},"you do not want to import ",[17,824,26],{},[155,826,827],{},"you want normal Python numeric behavior",[14,829,811,830,814],{},[17,831,19],{},[152,833,834,839,842],{},[155,835,836,837,260],{},"you are already using the ",[17,838,26],{},[155,840,841],{},"you are learning standard library math functions together",[155,843,844],{},"a float result is fine",[14,846,847,848,854],{},"If you want to clean up a float result for display, ",[278,849,851],{"href":850},"\u002Freference\u002Fpython-round-function-explained",[17,852,853],{},"round()"," can help.",[39,856,858],{"id":857},"when-beginners-should-use-mathpow","When beginners should use math.pow()",[14,860,861,863],{},[17,862,19],{}," is not wrong. It is just not always necessary.",[14,865,866],{},"It makes sense to use it when:",[152,868,869,874,877],{},[155,870,871,872],{},"you are already working with other functions from ",[17,873,26],{},[155,875,876],{},"you want to keep your code consistent with other math-module calls",[155,878,879],{},"a float result is acceptable",[14,881,882],{},"It is usually not necessary when:",[152,884,885,888,893],{},[155,886,887],{},"you only need simple exponentiation",[155,889,890,892],{},[17,891,36],{}," would be shorter and clearer",[155,894,895],{},"you expect an integer result",[14,897,898,899,901,902,904],{},"For many beginners, ",[17,900,36],{}," is the more natural choice, while ",[17,903,19],{}," is useful to recognize and understand.",[39,906,908],{"id":907},"common-errors-and-mistakes","Common errors and mistakes",[454,910,912],{"id":911},"forgetting-to-import-math","Forgetting to import math",[14,914,915,916,919,920,922],{},"This causes a ",[17,917,918],{},"NameError"," because Python does not know what ",[17,921,26],{}," is.",[44,924,926],{"className":46,"code":925,"language":48,"meta":49,"style":49},"print(math.pow(2, 3))\n",[17,927,928],{"__ignoreMap":49},[53,929,930,932,934,936,938,940,942,944,946,948],{"class":55,"line":56},[53,931,115],{"class":114},[53,933,95],{"class":87},[53,935,26],{"class":91},[53,937,88],{"class":87},[53,939,92],{"class":91},[53,941,95],{"class":87},[53,943,99],{"class":98},[53,945,102],{"class":87},[53,947,105],{"class":98},[53,949,950],{"class":87},"))\n",[14,952,953,954,956],{},"This fails because ",[17,955,26],{}," was never imported.",[14,958,959],{},"Fix it like this:",[44,961,963],{"className":46,"code":962,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(2, 3))\n",[17,964,965,971,975],{"__ignoreMap":49},[53,966,967,969],{"class":55,"line":56},[53,968,60],{"class":59},[53,970,64],{"class":63},[53,972,973],{"class":55,"line":67},[53,974,71],{"emptyLinePlaceholder":70},[53,976,977,979,981,983,985,987,989,991,993,995],{"class":55,"line":74},[53,978,115],{"class":114},[53,980,95],{"class":87},[53,982,26],{"class":91},[53,984,88],{"class":87},[53,986,92],{"class":91},[53,988,95],{"class":87},[53,990,99],{"class":98},[53,992,102],{"class":87},[53,994,105],{"class":98},[53,996,950],{"class":87},[14,998,999,1000,88],{},"If you see this kind of problem, read ",[278,1001,1003],{"href":1002},"\u002Ferrors\u002Fnameerror-name-is-not-defined-fix","NameError: name is not defined",[454,1005,1007,1008,1011],{"id":1006},"using-pow-like-a-method","Using ",[17,1009,1010],{},".pow()"," like a method",[14,1013,1014],{},"This is incorrect:",[44,1016,1018],{"className":46,"code":1017,"language":48,"meta":49,"style":49},"number = 4\nprint(number.pow(2))\n",[17,1019,1020,1030],{"__ignoreMap":49},[53,1021,1022,1025,1027],{"class":55,"line":56},[53,1023,1024],{"class":63},"number ",[53,1026,81],{"class":80},[53,1028,1029],{"class":98}," 4\n",[53,1031,1032,1034,1036,1039,1041,1043,1045,1047],{"class":55,"line":67},[53,1033,115],{"class":114},[53,1035,95],{"class":87},[53,1037,1038],{"class":91},"number",[53,1040,88],{"class":87},[53,1042,92],{"class":91},[53,1044,95],{"class":87},[53,1046,99],{"class":98},[53,1048,950],{"class":87},[14,1050,1051,1052,1054],{},"Numbers do not have a ",[17,1053,1010],{}," method.",[14,1056,1057],{},"Use this instead:",[44,1059,1061],{"className":46,"code":1060,"language":48,"meta":49,"style":49},"import math\n\nnumber = 4\nprint(math.pow(number, 2))  # 16.0\n",[17,1062,1063,1069,1073,1081],{"__ignoreMap":49},[53,1064,1065,1067],{"class":55,"line":56},[53,1066,60],{"class":59},[53,1068,64],{"class":63},[53,1070,1071],{"class":55,"line":67},[53,1072,71],{"emptyLinePlaceholder":70},[53,1074,1075,1077,1079],{"class":55,"line":74},[53,1076,1024],{"class":63},[53,1078,81],{"class":80},[53,1080,1029],{"class":98},[53,1082,1083,1085,1087,1089,1091,1093,1095,1097,1099,1101,1103],{"class":55,"line":111},[53,1084,115],{"class":114},[53,1086,95],{"class":87},[53,1088,26],{"class":91},[53,1090,88],{"class":87},[53,1092,92],{"class":91},[53,1094,95],{"class":87},[53,1096,1038],{"class":91},[53,1098,102],{"class":87},[53,1100,325],{"class":98},[53,1102,244],{"class":87},[53,1104,340],{"class":126},[14,1106,1107],{},"Or use the operator:",[44,1109,1111],{"className":46,"code":1110,"language":48,"meta":49,"style":49},"number = 4\nprint(number ** 2)  # 16\n",[17,1112,1113,1121],{"__ignoreMap":49},[53,1114,1115,1117,1119],{"class":55,"line":56},[53,1116,1024],{"class":63},[53,1118,81],{"class":80},[53,1120,1029],{"class":98},[53,1122,1123,1125,1127,1129,1131,1133,1135],{"class":55,"line":67},[53,1124,115],{"class":114},[53,1126,95],{"class":87},[53,1128,1024],{"class":91},[53,1130,36],{"class":80},[53,1132,325],{"class":98},[53,1134,123],{"class":87},[53,1136,1137],{"class":126},"  # 16\n",[454,1139,1141],{"id":1140},"expecting-an-int-instead-of-a-float","Expecting an int instead of a float",[14,1143,1144],{},"Many beginners expect this:",[44,1146,1147],{"className":46,"code":47,"language":48,"meta":49,"style":49},[17,1148,1149,1155,1159,1181],{"__ignoreMap":49},[53,1150,1151,1153],{"class":55,"line":56},[53,1152,60],{"class":59},[53,1154,64],{"class":63},[53,1156,1157],{"class":55,"line":67},[53,1158,71],{"emptyLinePlaceholder":70},[53,1160,1161,1163,1165,1167,1169,1171,1173,1175,1177,1179],{"class":55,"line":74},[53,1162,77],{"class":63},[53,1164,81],{"class":80},[53,1166,84],{"class":63},[53,1168,88],{"class":87},[53,1170,92],{"class":91},[53,1172,95],{"class":87},[53,1174,99],{"class":98},[53,1176,102],{"class":87},[53,1178,105],{"class":98},[53,1180,108],{"class":87},[53,1182,1183,1185,1187,1189,1191],{"class":55,"line":111},[53,1184,115],{"class":114},[53,1186,95],{"class":87},[53,1188,120],{"class":91},[53,1190,123],{"class":87},[53,1192,127],{"class":126},[14,1194,1195,1196,1198,1199,133,1201,88],{},"They expect ",[17,1197,777],{},", but ",[17,1200,19],{},[17,1202,769],{},[14,1204,1205],{},"If you need normal integer exponent behavior, use:",[44,1207,1209],{"className":46,"code":1208,"language":48,"meta":49,"style":49},"print(2 ** 3)  # 8\n",[17,1210,1211],{"__ignoreMap":49},[53,1212,1213,1215,1217,1219,1221,1223,1225],{"class":55,"line":56},[53,1214,115],{"class":114},[53,1216,95],{"class":87},[53,1218,99],{"class":98},[53,1220,748],{"class":80},[53,1222,105],{"class":98},[53,1224,123],{"class":87},[53,1226,1227],{"class":126},"  # 8\n",[454,1229,1231],{"id":1230},"passing-strings-instead-of-numbers","Passing strings instead of numbers",[14,1233,915,1234,378],{},[17,1235,1236],{},"TypeError",[44,1238,1240],{"className":46,"code":1239,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(\"2\", \"3\"))\n",[17,1241,1242,1248,1252],{"__ignoreMap":49},[53,1243,1244,1246],{"class":55,"line":56},[53,1245,60],{"class":59},[53,1247,64],{"class":63},[53,1249,1250],{"class":55,"line":67},[53,1251,71],{"emptyLinePlaceholder":70},[53,1253,1254,1256,1258,1260,1262,1264,1266,1270,1273,1275,1277,1280,1282,1284],{"class":55,"line":74},[53,1255,115],{"class":114},[53,1257,95],{"class":87},[53,1259,26],{"class":91},[53,1261,88],{"class":87},[53,1263,92],{"class":91},[53,1265,95],{"class":87},[53,1267,1269],{"class":1268},"sjJ54","\"",[53,1271,99],{"class":1272},"s_sjI",[53,1274,1269],{"class":1268},[53,1276,102],{"class":87},[53,1278,1279],{"class":1268}," \"",[53,1281,489],{"class":1272},[53,1283,1269],{"class":1268},[53,1285,950],{"class":87},[14,1287,1288],{},"Fix it by using numbers:",[44,1290,1291],{"className":46,"code":209,"language":48,"meta":49,"style":49},[17,1292,1293,1299,1303],{"__ignoreMap":49},[53,1294,1295,1297],{"class":55,"line":56},[53,1296,60],{"class":59},[53,1298,64],{"class":63},[53,1300,1301],{"class":55,"line":67},[53,1302,71],{"emptyLinePlaceholder":70},[53,1304,1305,1307,1309,1311,1313,1315,1317,1319,1321,1323,1325],{"class":55,"line":74},[53,1306,115],{"class":114},[53,1308,95],{"class":87},[53,1310,26],{"class":91},[53,1312,88],{"class":87},[53,1314,92],{"class":91},[53,1316,95],{"class":87},[53,1318,99],{"class":98},[53,1320,102],{"class":87},[53,1322,105],{"class":98},[53,1324,244],{"class":87},[53,1326,127],{"class":126},[14,1328,1329],{},"Or convert input values first:",[44,1331,1333],{"className":46,"code":1332,"language":48,"meta":49,"style":49},"import math\n\nx = \"2\"\ny = \"3\"\n\nprint(math.pow(float(x), float(y)))  # 8.0\n",[17,1334,1335,1341,1345,1359,1372,1376],{"__ignoreMap":49},[53,1336,1337,1339],{"class":55,"line":56},[53,1338,60],{"class":59},[53,1340,64],{"class":63},[53,1342,1343],{"class":55,"line":67},[53,1344,71],{"emptyLinePlaceholder":70},[53,1346,1347,1350,1352,1354,1356],{"class":55,"line":74},[53,1348,1349],{"class":63},"x ",[53,1351,81],{"class":80},[53,1353,1279],{"class":1268},[53,1355,99],{"class":1272},[53,1357,1358],{"class":1268},"\"\n",[53,1360,1361,1364,1366,1368,1370],{"class":55,"line":111},[53,1362,1363],{"class":63},"y ",[53,1365,81],{"class":80},[53,1367,1279],{"class":1268},[53,1369,489],{"class":1272},[53,1371,1358],{"class":1268},[53,1373,1374],{"class":55,"line":431},[53,1375,71],{"emptyLinePlaceholder":70},[53,1377,1379,1381,1383,1385,1387,1389,1391,1393,1395,1397,1400,1403,1405,1407,1410],{"class":55,"line":1378},6,[53,1380,115],{"class":114},[53,1382,95],{"class":87},[53,1384,26],{"class":91},[53,1386,88],{"class":87},[53,1388,92],{"class":91},[53,1390,95],{"class":87},[53,1392,273],{"class":438},[53,1394,95],{"class":87},[53,1396,136],{"class":91},[53,1398,1399],{"class":87},"),",[53,1401,1402],{"class":438}," float",[53,1404,95],{"class":87},[53,1406,140],{"class":91},[53,1408,1409],{"class":87},")))",[53,1411,127],{"class":126},[454,1413,1415],{"id":1414},"invalid-math-cases","Invalid math cases",[14,1417,1418,1419,1421,1422,88],{},"Some values are mathematically invalid for ",[17,1420,19],{}," and may raise ",[17,1423,1424],{},"ValueError",[14,1426,1427],{},"For example:",[44,1429,1431],{"className":46,"code":1430,"language":48,"meta":49,"style":49},"import math\n\nprint(math.pow(-9, 0.5))\n",[17,1432,1433,1439,1443],{"__ignoreMap":49},[53,1434,1435,1437],{"class":55,"line":56},[53,1436,60],{"class":59},[53,1438,64],{"class":63},[53,1440,1441],{"class":55,"line":67},[53,1442,71],{"emptyLinePlaceholder":70},[53,1444,1445,1447,1449,1451,1453,1455,1457,1460,1462,1464,1466],{"class":55,"line":74},[53,1446,115],{"class":114},[53,1448,95],{"class":87},[53,1450,26],{"class":91},[53,1452,88],{"class":87},[53,1454,92],{"class":91},[53,1456,95],{"class":87},[53,1458,1459],{"class":80},"-",[53,1461,657],{"class":98},[53,1463,102],{"class":87},[53,1465,662],{"class":98},[53,1467,950],{"class":87},[14,1469,1470],{},"This tries to take a square root of a negative number using real-number math, which is not allowed here.",[39,1472,1474],{"id":1473},"useful-related-functions","Useful related functions",[454,1476,1477],{"id":92},[17,1478,1479],{},"pow()",[14,1481,1482,1483,1485],{},"Python also has a built-in ",[17,1484,1479],{}," function.",[44,1487,1489],{"className":46,"code":1488,"language":48,"meta":49,"style":49},"print(pow(2, 3))  # 8\n",[17,1490,1491],{"__ignoreMap":49},[53,1492,1493,1495,1497,1499,1501,1503,1505,1507,1509],{"class":55,"line":56},[53,1494,115],{"class":114},[53,1496,95],{"class":87},[53,1498,92],{"class":114},[53,1500,95],{"class":87},[53,1502,99],{"class":98},[53,1504,102],{"class":87},[53,1506,105],{"class":98},[53,1508,244],{"class":87},[53,1510,1227],{"class":126},[14,1512,1513,1514,1516],{},"This is different from ",[17,1515,19],{}," because it does not always force the result to be a float.",[454,1518,1520],{"id":1519},"mathsqrt",[17,1521,680],{},[14,1523,1524,1525,1527,1528,88],{},"For square roots, ",[17,1526,680],{}," is often clearer than using an exponent like ",[17,1529,673],{},[44,1531,1533],{"className":46,"code":1532,"language":48,"meta":49,"style":49},"import math\n\nprint(math.sqrt(9))  # 3.0\n",[17,1534,1535,1541,1545],{"__ignoreMap":49},[53,1536,1537,1539],{"class":55,"line":56},[53,1538,60],{"class":59},[53,1540,64],{"class":63},[53,1542,1543],{"class":55,"line":67},[53,1544,71],{"emptyLinePlaceholder":70},[53,1546,1547,1549,1551,1553,1555,1558,1560,1562,1564],{"class":55,"line":74},[53,1548,115],{"class":114},[53,1550,95],{"class":87},[53,1552,26],{"class":91},[53,1554,88],{"class":87},[53,1556,1557],{"class":91},"sqrt",[53,1559,95],{"class":87},[53,1561,657],{"class":98},[53,1563,244],{"class":87},[53,1565,667],{"class":126},[14,1567,1568,1569,88],{},"See ",[278,1570,1571,1573],{"href":677},[17,1572,680],{}," explained",[454,1575,1577,691,1580],{"id":1576},"mathceil-and-mathfloor",[17,1578,1579],{},"math.ceil()",[17,1581,1582],{},"math.floor()",[14,1584,1585],{},"These are useful when you are working with float results and want to move up or down to a whole number.",[44,1587,1589],{"className":46,"code":1588,"language":48,"meta":49,"style":49},"import math\n\nvalue = math.pow(2, 3) \u002F 3\nprint(value)             # 2.6666666666666665\nprint(math.ceil(value))  # 3\nprint(math.floor(value)) # 2\n",[17,1590,1591,1597,1601,1630,1644,1666],{"__ignoreMap":49},[53,1592,1593,1595],{"class":55,"line":56},[53,1594,60],{"class":59},[53,1596,64],{"class":63},[53,1598,1599],{"class":55,"line":67},[53,1600,71],{"emptyLinePlaceholder":70},[53,1602,1603,1606,1608,1610,1612,1614,1616,1618,1620,1622,1624,1627],{"class":55,"line":74},[53,1604,1605],{"class":63},"value ",[53,1607,81],{"class":80},[53,1609,84],{"class":63},[53,1611,88],{"class":87},[53,1613,92],{"class":91},[53,1615,95],{"class":87},[53,1617,99],{"class":98},[53,1619,102],{"class":87},[53,1621,105],{"class":98},[53,1623,123],{"class":87},[53,1625,1626],{"class":80}," \u002F",[53,1628,1629],{"class":98}," 3\n",[53,1631,1632,1634,1636,1639,1641],{"class":55,"line":111},[53,1633,115],{"class":114},[53,1635,95],{"class":87},[53,1637,1638],{"class":91},"value",[53,1640,123],{"class":87},[53,1642,1643],{"class":126},"             # 2.6666666666666665\n",[53,1645,1646,1648,1650,1652,1654,1657,1659,1661,1663],{"class":55,"line":431},[53,1647,115],{"class":114},[53,1649,95],{"class":87},[53,1651,26],{"class":91},[53,1653,88],{"class":87},[53,1655,1656],{"class":91},"ceil",[53,1658,95],{"class":87},[53,1660,1638],{"class":91},[53,1662,244],{"class":87},[53,1664,1665],{"class":126},"  # 3\n",[53,1667,1668,1670,1672,1674,1676,1679,1681,1683,1685],{"class":55,"line":1378},[53,1669,115],{"class":114},[53,1671,95],{"class":87},[53,1673,26],{"class":91},[53,1675,88],{"class":87},[53,1677,1678],{"class":91},"floor",[53,1680,95],{"class":87},[53,1682,1638],{"class":91},[53,1684,244],{"class":87},[53,1686,1687],{"class":126}," # 2\n",[454,1689,1691],{"id":1690},"round",[17,1692,853],{},[14,1694,811,1695,1697],{},[17,1696,853],{}," when you want cleaner output.",[44,1699,1701],{"className":46,"code":1700,"language":48,"meta":49,"style":49},"import math\n\nvalue = math.pow(2, -1)\nprint(value)          # 0.5\nprint(round(value, 1))  # 0.5\n",[17,1702,1703,1709,1713,1737,1750],{"__ignoreMap":49},[53,1704,1705,1707],{"class":55,"line":56},[53,1706,60],{"class":59},[53,1708,64],{"class":63},[53,1710,1711],{"class":55,"line":67},[53,1712,71],{"emptyLinePlaceholder":70},[53,1714,1715,1717,1719,1721,1723,1725,1727,1729,1731,1733,1735],{"class":55,"line":74},[53,1716,1605],{"class":63},[53,1718,81],{"class":80},[53,1720,84],{"class":63},[53,1722,88],{"class":87},[53,1724,92],{"class":91},[53,1726,95],{"class":87},[53,1728,99],{"class":98},[53,1730,102],{"class":87},[53,1732,600],{"class":80},[53,1734,560],{"class":98},[53,1736,108],{"class":87},[53,1738,1739,1741,1743,1745,1747],{"class":55,"line":111},[53,1740,115],{"class":114},[53,1742,95],{"class":87},[53,1744,1638],{"class":91},[53,1746,123],{"class":87},[53,1748,1749],{"class":126},"          # 0.5\n",[53,1751,1752,1754,1756,1758,1760,1762,1764,1767,1769],{"class":55,"line":431},[53,1753,115],{"class":114},[53,1755,95],{"class":87},[53,1757,1690],{"class":114},[53,1759,95],{"class":87},[53,1761,1638],{"class":91},[53,1763,102],{"class":87},[53,1765,1766],{"class":98}," 1",[53,1768,244],{"class":87},[53,1770,607],{"class":126},[14,1772,1773,1774,88],{},"You can also read ",[278,1775,1776],{"href":850},"Python round() explained",[39,1778,1780],{"id":1779},"faq","FAQ",[454,1782,1784],{"id":1783},"what-does-mathpow-do-in-python","What does math.pow() do in Python?",[14,1786,1787],{},"It raises one number to the power of another and returns the result as a float.",[454,1789,1791],{"id":1790},"do-i-need-to-import-math-to-use-mathpow","Do I need to import math to use math.pow()?",[14,1793,1794,1795,1797,1798,1800,1801,1803],{},"Yes. ",[17,1796,19],{}," is part of the ",[17,1799,26],{}," module, so you must write ",[17,1802,266],{}," first.",[454,1805,1807],{"id":1806},"what-is-the-difference-between-mathpow-and-in-python","What is the difference between math.pow() and ** in Python?",[14,1809,1810,1812,1813,1815,1816,1818,1819,88],{},[17,1811,19],{}," always returns a float and requires ",[17,1814,266],{},". The ",[17,1817,36],{}," operator does not need an import and may return an ",[17,1820,1821],{},"int",[454,1823,1825],{"id":1824},"why-does-mathpow2-3-return-80-instead-of-8","Why does math.pow(2, 3) return 8.0 instead of 8?",[14,1827,1828,1829,1831],{},"Because ",[17,1830,19],{}," returns a float result, even when the answer is a whole number.",[454,1833,1835],{"id":1834},"can-mathpow-use-negative-exponents","Can math.pow() use negative exponents?",[14,1837,1838,1839,133,1842,88],{},"Yes. For example, ",[17,1840,1841],{},"math.pow(2, -1)",[17,1843,673],{},[39,1845,1847],{"id":1846},"see-also","See also",[152,1849,1850,1854,1859,1863,1869],{},[155,1851,1852],{},[278,1853,281],{"href":280},[155,1855,1856],{},[278,1857,1858],{"href":677},"math.sqrt() function explained",[155,1860,1861],{},[278,1862,1776],{"href":850},[155,1864,1865],{},[278,1866,1868],{"href":1867},"\u002Freference\u002Fpython-abs-function-explained","Python abs() explained",[155,1870,1871],{},[278,1872,1003],{"href":1002},[1874,1875,1876],"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":49,"searchDepth":67,"depth":67,"links":1878},[1879,1880,1881,1882,1888,1893,1894,1902,1909,1916],{"id":41,"depth":67,"text":42},{"id":144,"depth":67,"text":145},{"id":284,"depth":67,"text":285},{"id":451,"depth":67,"text":452,"children":1883},[1884,1885,1886,1887],{"id":456,"depth":74,"text":457},{"id":507,"depth":74,"text":508},{"id":563,"depth":74,"text":564},{"id":624,"depth":74,"text":625},{"id":684,"depth":67,"text":685,"children":1889},[1890,1891,1892],{"id":697,"depth":74,"text":698},{"id":758,"depth":74,"text":759},{"id":802,"depth":74,"text":803},{"id":857,"depth":67,"text":858},{"id":907,"depth":67,"text":908,"children":1895},[1896,1897,1899,1900,1901],{"id":911,"depth":74,"text":912},{"id":1006,"depth":74,"text":1898},"Using .pow() like a method",{"id":1140,"depth":74,"text":1141},{"id":1230,"depth":74,"text":1231},{"id":1414,"depth":74,"text":1415},{"id":1473,"depth":67,"text":1474,"children":1903},[1904,1905,1906,1908],{"id":92,"depth":74,"text":1479},{"id":1519,"depth":74,"text":680},{"id":1576,"depth":74,"text":1907},"math.ceil() and math.floor()",{"id":1690,"depth":74,"text":853},{"id":1779,"depth":67,"text":1780,"children":1910},[1911,1912,1913,1914,1915],{"id":1783,"depth":74,"text":1784},{"id":1790,"depth":74,"text":1791},{"id":1806,"depth":74,"text":1807},{"id":1824,"depth":74,"text":1825},{"id":1834,"depth":74,"text":1835},{"id":1846,"depth":67,"text":1847},"Master math.pow function explained in our comprehensive Python beginner guide.","md",{},"\u002Fstandard-library\u002Fmath.pow-function-explained",{"title":5,"description":1917},"standard-library\u002Fmath.pow-function-explained","4rEQE9HwUMZpH-UtAnBTUiON7JO-CZ-8b0jtmqxvBME",1777585468655]