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