[{"data":1,"prerenderedAt":1287},["ShallowReactive",2],{"doc-\u002Ferrors\u002Fvalueerror-could-not-convert-string-to-float-fix":3},{"id":4,"title":5,"body":6,"description":1280,"extension":1281,"meta":1282,"navigation":118,"path":1283,"seo":1284,"stem":1285,"__hash__":1286},"content\u002Ferrors\u002Fvalueerror-could-not-convert-string-to-float-fix.md","ValueError: could not convert string to float (Fix)",{"type":7,"value":8,"toc":1259},"minimark",[9,13,22,25,30,189,200,204,210,215,234,237,254,265,269,272,292,298,302,305,342,345,379,386,390,393,430,433,461,465,468,471,495,502,506,509,512,614,616,626,629,654,663,667,670,673,769,772,779,783,788,791,883,886,897,905,909,914,917,995,998,1020,1023,1099,1101,1133,1136,1140,1143,1173,1177,1185,1195,1199,1205,1209,1212,1216,1219,1223,1255],[10,11,5],"h1",{"id":12},"valueerror-could-not-convert-string-to-float-fix",[14,15,16,17,21],"p",{},"This error happens when you call ",[18,19,20],"code",{},"float()"," with text that is not a valid number.",[14,23,24],{},"It often appears when you read input from a user, a file, a CSV, or an API. The fix is usually to inspect the string, clean it if needed, and handle bad input safely.",[26,27,29],"h2",{"id":28},"quick-fix","Quick fix",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","text = input(\"Enter a number: \").strip()\ntext = text.replace(\",\", \"\")\n\ntry:\n    number = float(text)\n    print(number)\nexcept ValueError:\n    print(\"Please enter a valid number, such as 3.14 or 10\")\n","python","",[18,38,39,80,113,120,130,149,162,173],{"__ignoreMap":36},[40,41,44,48,52,56,60,64,68,70,73,77],"span",{"class":42,"line":43},"line",1,[40,45,47],{"class":46},"su5hD","text ",[40,49,51],{"class":50},"smGrS","=",[40,53,55],{"class":54},"sptTA"," input",[40,57,59],{"class":58},"sP7_E","(",[40,61,63],{"class":62},"sjJ54","\"",[40,65,67],{"class":66},"s_sjI","Enter a number: ",[40,69,63],{"class":62},[40,71,72],{"class":58},").",[40,74,76],{"class":75},"slqww","strip",[40,78,79],{"class":58},"()\n",[40,81,83,85,87,90,93,96,98,100,103,105,107,110],{"class":42,"line":82},2,[40,84,47],{"class":46},[40,86,51],{"class":50},[40,88,89],{"class":46}," text",[40,91,92],{"class":58},".",[40,94,95],{"class":75},"replace",[40,97,59],{"class":58},[40,99,63],{"class":62},[40,101,102],{"class":66},",",[40,104,63],{"class":62},[40,106,102],{"class":58},[40,108,109],{"class":62}," \"\"",[40,111,112],{"class":58},")\n",[40,114,116],{"class":42,"line":115},3,[40,117,119],{"emptyLinePlaceholder":118},true,"\n",[40,121,123,127],{"class":42,"line":122},4,[40,124,126],{"class":125},"sVHd0","try",[40,128,129],{"class":58},":\n",[40,131,133,136,138,142,144,147],{"class":42,"line":132},5,[40,134,135],{"class":46},"    number ",[40,137,51],{"class":50},[40,139,141],{"class":140},"sZMiF"," float",[40,143,59],{"class":58},[40,145,146],{"class":75},"text",[40,148,112],{"class":58},[40,150,152,155,157,160],{"class":42,"line":151},6,[40,153,154],{"class":54},"    print",[40,156,59],{"class":58},[40,158,159],{"class":75},"number",[40,161,112],{"class":58},[40,163,165,168,171],{"class":42,"line":164},7,[40,166,167],{"class":125},"except",[40,169,170],{"class":140}," ValueError",[40,172,129],{"class":58},[40,174,176,178,180,182,185,187],{"class":42,"line":175},8,[40,177,154],{"class":54},[40,179,59],{"class":58},[40,181,63],{"class":62},[40,183,184],{"class":66},"Please enter a valid number, such as 3.14 or 10",[40,186,63],{"class":62},[40,188,112],{"class":58},[14,190,191,192,195,196,199],{},"Use ",[18,193,194],{},"strip()"," to remove extra spaces, clean the input if needed, and catch ",[18,197,198],{},"ValueError"," when the text is not a valid decimal number.",[26,201,203],{"id":202},"what-this-error-means","What this error means",[14,205,206,207,209],{},"Python raises this error when ",[18,208,20],{}," receives a string that does not match a valid floating-point number.",[14,211,212,214],{},[18,213,20],{}," can convert strings like:",[216,217,218,224,229],"ul",{},[219,220,221],"li",{},[18,222,223],{},"'3.14'",[219,225,226],{},[18,227,228],{},"'10'",[219,230,231],{},[18,232,233],{},"' 5.0 '",[14,235,236],{},"But it cannot convert strings like:",[216,238,239,244,249],{},[219,240,241],{},[18,242,243],{},"'hello'",[219,245,246],{},[18,247,248],{},"'3,14'",[219,250,251],{},[18,252,253],{},"''",[14,255,256,257,92],{},"If you need a basic explanation of how conversion works, see the ",[258,259,261,262,264],"a",{"href":260},"\u002Freference\u002Fpython-float-function-explained\u002F","Python ",[18,263,20],{}," function explained",[26,266,268],{"id":267},"when-this-error-happens","When this error happens",[14,270,271],{},"This error commonly appears when you are:",[216,273,274,283,286,289],{},[219,275,276,277],{},"Converting user input from ",[258,278,280],{"href":279},"\u002Freference\u002Fpython-input-function-explained\u002F",[18,281,282],{},"input()",[219,284,285],{},"Reading numbers from a file or CSV",[219,287,288],{},"Parsing text from an API or web page",[219,290,291],{},"Trying to convert strings that contain symbols, commas, or words",[14,293,294,295,297],{},"In short, the problem is usually not ",[18,296,20],{}," itself. The problem is the string you passed into it.",[26,299,301],{"id":300},"example-that-causes-the-error","Example that causes the error",[14,303,304],{},"Here is a minimal example:",[31,306,308],{"className":33,"code":307,"language":35,"meta":36,"style":36},"value = \"abc\"\nnumber = float(value)\n",[18,309,310,326],{"__ignoreMap":36},[40,311,312,315,317,320,323],{"class":42,"line":43},[40,313,314],{"class":46},"value ",[40,316,51],{"class":50},[40,318,319],{"class":62}," \"",[40,321,322],{"class":66},"abc",[40,324,325],{"class":62},"\"\n",[40,327,328,331,333,335,337,340],{"class":42,"line":82},[40,329,330],{"class":46},"number ",[40,332,51],{"class":50},[40,334,141],{"class":140},[40,336,59],{"class":58},[40,338,339],{"class":75},"value",[40,341,112],{"class":58},[14,343,344],{},"Output:",[31,346,348],{"className":33,"code":347,"language":35,"meta":36,"style":36},"ValueError: could not convert string to float: 'abc'\n",[18,349,350],{"__ignoreMap":36},[40,351,352,354,357,360,363,366,369,371,374,376],{"class":42,"line":43},[40,353,198],{"class":140},[40,355,356],{"class":58},":",[40,358,359],{"class":46}," could ",[40,361,362],{"class":50},"not",[40,364,365],{"class":46}," convert string to ",[40,367,368],{"class":140},"float",[40,370,356],{"class":58},[40,372,373],{"class":62}," '",[40,375,322],{"class":66},[40,377,378],{"class":62},"'\n",[14,380,381,382,385],{},"This fails because ",[18,383,384],{},"\"abc\""," is text, not a valid number format.",[26,387,389],{"id":388},"common-causes","Common causes",[14,391,392],{},"These are some of the most common reasons this error happens:",[216,394,395,401,406,415,421,427],{},[219,396,397,398],{},"Letters inside the string, such as ",[18,399,400],{},"'12a'",[219,402,403,404],{},"Empty strings, such as ",[18,405,253],{},[219,407,408,409,412,413],{},"Commas used as separators, such as ",[18,410,411],{},"'1,234'"," or ",[18,414,248],{},[219,416,417,418],{},"Currency symbols, such as ",[18,419,420],{},"'$19.99'",[219,422,423,424],{},"Trailing text, such as ",[18,425,426],{},"'4.2kg'",[219,428,429],{},"Input with only spaces",[14,431,432],{},"Other common cases include:",[216,434,435,443,446,455,458],{},[219,436,437,438,440,441],{},"Calling ",[18,439,20],{}," on text like ",[18,442,243],{},[219,444,445],{},"Trying to convert an empty string",[219,447,448,449,412,452],{},"Including symbols like ",[18,450,451],{},"'$'",[18,453,454],{},"'%'",[219,456,457],{},"Reading file data with hidden newline characters or extra text",[219,459,460],{},"Assuming all user input is numeric",[26,462,464],{"id":463},"how-to-fix-it","How to fix it",[14,466,467],{},"The best fix depends on where the string comes from.",[14,469,470],{},"In general:",[216,472,473,476,481,484,490],{},[219,474,475],{},"Check the original string before converting it",[219,477,191,478,480],{},[18,479,194],{}," to remove leading and trailing spaces",[219,482,483],{},"Remove formatting characters only if you expect them",[219,485,191,486,489],{},[18,487,488],{},"try-except"," to handle invalid input safely",[219,491,492,493],{},"Validate user input before calling ",[18,494,20],{},[14,496,497,498,92],{},"If your goal is general conversion, see ",[258,499,501],{"href":500},"\u002Fhow-to\u002Fhow-to-convert-string-to-float-in-python\u002F","how to convert string to float in Python",[26,503,505],{"id":504},"fix-option-1-clean-the-string-first","Fix option 1: Clean the string first",[14,507,508],{},"This is useful when the number may include known formatting characters such as spaces, commas, or a currency symbol.",[14,510,511],{},"Only remove characters you are sure should not be there.",[31,513,515],{"className":33,"code":514,"language":35,"meta":36,"style":36},"value = \" $1,234.50 \\n\"\ncleaned = value.strip().replace(\"$\", \"\").replace(\",\", \"\")\nnumber = float(cleaned)\n\nprint(number)\n",[18,516,517,534,584,599,603],{"__ignoreMap":36},[40,518,519,521,523,525,528,532],{"class":42,"line":43},[40,520,314],{"class":46},[40,522,51],{"class":50},[40,524,319],{"class":62},[40,526,527],{"class":66}," $1,234.50 ",[40,529,531],{"class":530},"s_hVV","\\n",[40,533,325],{"class":62},[40,535,536,539,541,544,546,548,551,553,555,557,560,562,564,566,568,570,572,574,576,578,580,582],{"class":42,"line":82},[40,537,538],{"class":46},"cleaned ",[40,540,51],{"class":50},[40,542,543],{"class":46}," value",[40,545,92],{"class":58},[40,547,76],{"class":75},[40,549,550],{"class":58},"().",[40,552,95],{"class":75},[40,554,59],{"class":58},[40,556,63],{"class":62},[40,558,559],{"class":66},"$",[40,561,63],{"class":62},[40,563,102],{"class":58},[40,565,109],{"class":62},[40,567,72],{"class":58},[40,569,95],{"class":75},[40,571,59],{"class":58},[40,573,63],{"class":62},[40,575,102],{"class":66},[40,577,63],{"class":62},[40,579,102],{"class":58},[40,581,109],{"class":62},[40,583,112],{"class":58},[40,585,586,588,590,592,594,597],{"class":42,"line":115},[40,587,330],{"class":46},[40,589,51],{"class":50},[40,591,141],{"class":140},[40,593,59],{"class":58},[40,595,596],{"class":75},"cleaned",[40,598,112],{"class":58},[40,600,601],{"class":42,"line":122},[40,602,119],{"emptyLinePlaceholder":118},[40,604,605,608,610,612],{"class":42,"line":132},[40,606,607],{"class":54},"print",[40,609,59],{"class":58},[40,611,159],{"class":75},[40,613,112],{"class":58},[14,615,344],{},[31,617,619],{"className":33,"code":618,"language":35,"meta":36,"style":36},"1234.5\n",[18,620,621],{"__ignoreMap":36},[40,622,623],{"class":42,"line":43},[40,624,618],{"class":625},"srdBf",[14,627,628],{},"What this code does:",[216,630,631,636,642,648],{},[219,632,633,635],{},[18,634,194],{}," removes spaces and newline characters at the start and end",[219,637,638,641],{},[18,639,640],{},"replace(\"$\", \"\")"," removes the dollar sign",[219,643,644,647],{},[18,645,646],{},"replace(\",\", \"\")"," removes the thousands separator",[219,649,650,653],{},[18,651,652],{},"float(cleaned)"," converts the cleaned string",[14,655,656,657,659,660,662],{},"Be careful with values like ",[18,658,248],{},". In normal Python usage, ",[18,661,20],{}," expects a dot for decimals, not a comma.",[26,664,666],{"id":665},"fix-option-2-use-try-except","Fix option 2: Use try-except",[14,668,669],{},"This is the safest choice when the input may be invalid.",[14,671,672],{},"It prevents your program from crashing and lets you show a helpful message.",[31,674,676],{"className":33,"code":675,"language":35,"meta":36,"style":36},"value = input(\"Enter a price: \").strip()\n\ntry:\n    price = float(value)\n    print(\"You entered:\", price)\nexcept ValueError:\n    print(\"That is not a valid number.\")\n",[18,677,678,701,705,711,726,746,754],{"__ignoreMap":36},[40,679,680,682,684,686,688,690,693,695,697,699],{"class":42,"line":43},[40,681,314],{"class":46},[40,683,51],{"class":50},[40,685,55],{"class":54},[40,687,59],{"class":58},[40,689,63],{"class":62},[40,691,692],{"class":66},"Enter a price: ",[40,694,63],{"class":62},[40,696,72],{"class":58},[40,698,76],{"class":75},[40,700,79],{"class":58},[40,702,703],{"class":42,"line":82},[40,704,119],{"emptyLinePlaceholder":118},[40,706,707,709],{"class":42,"line":115},[40,708,126],{"class":125},[40,710,129],{"class":58},[40,712,713,716,718,720,722,724],{"class":42,"line":122},[40,714,715],{"class":46},"    price ",[40,717,51],{"class":50},[40,719,141],{"class":140},[40,721,59],{"class":58},[40,723,339],{"class":75},[40,725,112],{"class":58},[40,727,728,730,732,734,737,739,741,744],{"class":42,"line":132},[40,729,154],{"class":54},[40,731,59],{"class":58},[40,733,63],{"class":62},[40,735,736],{"class":66},"You entered:",[40,738,63],{"class":62},[40,740,102],{"class":58},[40,742,743],{"class":75}," price",[40,745,112],{"class":58},[40,747,748,750,752],{"class":42,"line":151},[40,749,167],{"class":125},[40,751,170],{"class":140},[40,753,129],{"class":58},[40,755,756,758,760,762,765,767],{"class":42,"line":164},[40,757,154],{"class":54},[40,759,59],{"class":58},[40,761,63],{"class":62},[40,763,764],{"class":66},"That is not a valid number.",[40,766,63],{"class":62},[40,768,112],{"class":58},[14,770,771],{},"This approach is especially useful for user input, files, and external data.",[14,773,774,775,92],{},"If you often work with user-entered values, see ",[258,776,778],{"href":777},"\u002Fhow-to\u002Fhow-to-convert-user-input-to-numbers-in-python\u002F","how to convert user input to numbers in Python",[26,780,782],{"id":781},"fix-option-3-check-for-empty-input","Fix option 3: Check for empty input",[14,784,785,786,92],{},"An empty string cannot be converted with ",[18,787,20],{},[14,789,790],{},"Handle blank input before conversion:",[31,792,794],{"className":33,"code":793,"language":35,"meta":36,"style":36},"value = input(\"Enter a number: \").strip()\n\nif value == \"\":\n    print(\"Input cannot be empty.\")\nelse:\n    number = float(value)\n    print(number)\n",[18,795,796,818,822,837,852,859,873],{"__ignoreMap":36},[40,797,798,800,802,804,806,808,810,812,814,816],{"class":42,"line":43},[40,799,314],{"class":46},[40,801,51],{"class":50},[40,803,55],{"class":54},[40,805,59],{"class":58},[40,807,63],{"class":62},[40,809,67],{"class":66},[40,811,63],{"class":62},[40,813,72],{"class":58},[40,815,76],{"class":75},[40,817,79],{"class":58},[40,819,820],{"class":42,"line":82},[40,821,119],{"emptyLinePlaceholder":118},[40,823,824,827,830,833,835],{"class":42,"line":115},[40,825,826],{"class":125},"if",[40,828,829],{"class":46}," value ",[40,831,832],{"class":50},"==",[40,834,109],{"class":62},[40,836,129],{"class":58},[40,838,839,841,843,845,848,850],{"class":42,"line":122},[40,840,154],{"class":54},[40,842,59],{"class":58},[40,844,63],{"class":62},[40,846,847],{"class":66},"Input cannot be empty.",[40,849,63],{"class":62},[40,851,112],{"class":58},[40,853,854,857],{"class":42,"line":132},[40,855,856],{"class":125},"else",[40,858,129],{"class":58},[40,860,861,863,865,867,869,871],{"class":42,"line":151},[40,862,135],{"class":46},[40,864,51],{"class":50},[40,866,141],{"class":140},[40,868,59],{"class":58},[40,870,339],{"class":75},[40,872,112],{"class":58},[40,874,875,877,879,881],{"class":42,"line":164},[40,876,154],{"class":54},[40,878,59],{"class":58},[40,880,159],{"class":75},[40,882,112],{"class":58},[14,884,885],{},"This is useful in:",[216,887,888,891,894],{},[219,889,890],{},"Forms",[219,892,893],{},"Command-line tools",[219,895,896],{},"User prompts",[14,898,899,900,902,903,92],{},"It also helps with strings that contain only spaces, because ",[18,901,194],{}," turns them into ",[18,904,253],{},[26,906,908],{"id":907},"debugging-steps","Debugging steps",[14,910,911,912,92],{},"If you are not sure why the conversion fails, inspect the value before calling ",[18,913,20],{},[14,915,916],{},"Useful debugging commands:",[31,918,920],{"className":33,"code":919,"language":35,"meta":36,"style":36},"print(value)\nprint(repr(value))\nprint(type(value))\n\ncleaned = value.strip()\nprint(repr(cleaned))\n",[18,921,922,932,948,963,967,981],{"__ignoreMap":36},[40,923,924,926,928,930],{"class":42,"line":43},[40,925,607],{"class":54},[40,927,59],{"class":58},[40,929,339],{"class":75},[40,931,112],{"class":58},[40,933,934,936,938,941,943,945],{"class":42,"line":82},[40,935,607],{"class":54},[40,937,59],{"class":58},[40,939,940],{"class":54},"repr",[40,942,59],{"class":58},[40,944,339],{"class":75},[40,946,947],{"class":58},"))\n",[40,949,950,952,954,957,959,961],{"class":42,"line":115},[40,951,607],{"class":54},[40,953,59],{"class":58},[40,955,956],{"class":140},"type",[40,958,59],{"class":58},[40,960,339],{"class":75},[40,962,947],{"class":58},[40,964,965],{"class":42,"line":122},[40,966,119],{"emptyLinePlaceholder":118},[40,968,969,971,973,975,977,979],{"class":42,"line":132},[40,970,538],{"class":46},[40,972,51],{"class":50},[40,974,543],{"class":46},[40,976,92],{"class":58},[40,978,76],{"class":75},[40,980,79],{"class":58},[40,982,983,985,987,989,991,993],{"class":42,"line":151},[40,984,607],{"class":54},[40,986,59],{"class":58},[40,988,940],{"class":54},[40,990,59],{"class":58},[40,992,596],{"class":75},[40,994,947],{"class":58},[14,996,997],{},"What to check:",[216,999,1000,1006,1012,1015],{},[219,1001,1002,1003,1005],{},"Print the value before ",[18,1004,20],{}," to see what it really contains",[219,1007,191,1008,1011],{},[18,1009,1010],{},"repr(value)"," to reveal hidden spaces or newline characters",[219,1013,1014],{},"Check the exact source of the string: user input, file, API, or calculation",[219,1016,1017,1018],{},"Test with a known valid value like ",[18,1019,223],{},[14,1021,1022],{},"Example:",[31,1024,1026],{"className":33,"code":1025,"language":35,"meta":36,"style":36},"value = \"12.5\\n\"\n\nprint(value)\nprint(repr(value))\n\nnumber = float(value)\nprint(number)\n",[18,1027,1028,1043,1047,1057,1071,1075,1089],{"__ignoreMap":36},[40,1029,1030,1032,1034,1036,1039,1041],{"class":42,"line":43},[40,1031,314],{"class":46},[40,1033,51],{"class":50},[40,1035,319],{"class":62},[40,1037,1038],{"class":66},"12.5",[40,1040,531],{"class":530},[40,1042,325],{"class":62},[40,1044,1045],{"class":42,"line":82},[40,1046,119],{"emptyLinePlaceholder":118},[40,1048,1049,1051,1053,1055],{"class":42,"line":115},[40,1050,607],{"class":54},[40,1052,59],{"class":58},[40,1054,339],{"class":75},[40,1056,112],{"class":58},[40,1058,1059,1061,1063,1065,1067,1069],{"class":42,"line":122},[40,1060,607],{"class":54},[40,1062,59],{"class":58},[40,1064,940],{"class":54},[40,1066,59],{"class":58},[40,1068,339],{"class":75},[40,1070,947],{"class":58},[40,1072,1073],{"class":42,"line":132},[40,1074,119],{"emptyLinePlaceholder":118},[40,1076,1077,1079,1081,1083,1085,1087],{"class":42,"line":151},[40,1078,330],{"class":46},[40,1080,51],{"class":50},[40,1082,141],{"class":140},[40,1084,59],{"class":58},[40,1086,339],{"class":75},[40,1088,112],{"class":58},[40,1090,1091,1093,1095,1097],{"class":42,"line":164},[40,1092,607],{"class":54},[40,1094,59],{"class":58},[40,1096,159],{"class":75},[40,1098,112],{"class":58},[14,1100,344],{},[31,1102,1104],{"className":33,"code":1103,"language":35,"meta":36,"style":36},"12.5\n\n'12.5\\n'\n12.5\n",[18,1105,1106,1111,1115,1129],{"__ignoreMap":36},[40,1107,1108],{"class":42,"line":43},[40,1109,1110],{"class":625},"12.5\n",[40,1112,1113],{"class":42,"line":82},[40,1114,119],{"emptyLinePlaceholder":118},[40,1116,1117,1121,1124,1127],{"class":42,"line":115},[40,1118,1120],{"class":1119},"s2W-s","'",[40,1122,1038],{"class":1123},"sithA",[40,1125,531],{"class":1126},"sfi6f",[40,1128,378],{"class":1119},[40,1130,1131],{"class":42,"line":122},[40,1132,1110],{"class":625},[14,1134,1135],{},"In this case, the newline does not cause a problem. But hidden characters plus extra text often do.",[26,1137,1139],{"id":1138},"related-errors-to-compare","Related errors to compare",[14,1141,1142],{},"Sometimes a similar error has a different cause.",[216,1144,1145,1160,1167],{},[219,1146,1147,1153,1154,1157,1158],{},[258,1148,1150],{"href":1149},"\u002Ferrors\u002Fvalueerror-invalid-literal-for-int-with-base-10-fix\u002F",[18,1151,1152],{},"ValueError: invalid literal for int() with base 10"," happens when ",[18,1155,1156],{},"int()"," fails instead of ",[18,1159,20],{},[219,1161,1162,1166],{},[258,1163,1165],{"href":1164},"\u002Ferrors\u002Fvalueerror-in-python-causes-and-fixes\u002F","ValueError in Python: causes and fixes"," explains the broader exception type",[219,1168,1169,1172],{},[18,1170,1171],{},"TypeError"," can happen when the problem is the wrong data type, not bad string content",[26,1174,1176],{"id":1175},"faq","FAQ",[1178,1179,1181,1182,1184],"h3",{"id":1180},"can-float-convert-an-integer-string-like-10","Can float() convert an integer string like ",[18,1183,228],{},"?",[14,1186,1187,1188,1191,1192,92],{},"Yes. ",[18,1189,1190],{},"float('10')"," works and returns ",[18,1193,1194],{},"10.0",[1178,1196,1198],{"id":1197},"why-does-float314-fail","Why does float('3,14') fail?",[14,1200,1201,1202,1204],{},"Because ",[18,1203,20],{}," expects a dot as the decimal separator in normal Python usage, not a comma.",[1178,1206,1208],{"id":1207},"does-float-ignore-spaces","Does float() ignore spaces?",[14,1210,1211],{},"Leading and trailing spaces are usually fine, but strings with only spaces still fail after stripping.",[1178,1213,1215],{"id":1214},"should-i-always-use-try-except-with-float","Should I always use try-except with float()?",[14,1217,1218],{},"Use it when the input may be invalid, especially with user input, files, or external data.",[26,1220,1222],{"id":1221},"see-also","See also",[216,1224,1225,1231,1236,1242,1246,1250],{},[219,1226,1227],{},[258,1228,261,1229,264],{"href":260},[18,1230,20],{},[219,1232,1233],{},[258,1234,1235],{"href":500},"How to convert string to float in Python",[219,1237,1238],{},[258,1239,261,1240,264],{"href":279},[18,1241,282],{},[219,1243,1244],{},[258,1245,1152],{"href":1149},[219,1247,1248],{},[258,1249,1165],{"href":1164},[219,1251,1252],{},[258,1253,1254],{"href":777},"How to convert user input to numbers in Python",[1256,1257,1258],"style",{},"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 .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 .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html 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 .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .s2W-s, html code.shiki .s2W-s{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sithA, html code.shiki .sithA{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sfi6f, html code.shiki .sfi6f{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#005CC5;--shiki-default-font-style:inherit;--shiki-dark:#79B8FF;--shiki-dark-font-style:inherit}",{"title":36,"searchDepth":82,"depth":82,"links":1260},[1261,1262,1263,1264,1265,1266,1267,1268,1269,1270,1271,1272,1279],{"id":28,"depth":82,"text":29},{"id":202,"depth":82,"text":203},{"id":267,"depth":82,"text":268},{"id":300,"depth":82,"text":301},{"id":388,"depth":82,"text":389},{"id":463,"depth":82,"text":464},{"id":504,"depth":82,"text":505},{"id":665,"depth":82,"text":666},{"id":781,"depth":82,"text":782},{"id":907,"depth":82,"text":908},{"id":1138,"depth":82,"text":1139},{"id":1175,"depth":82,"text":1176,"children":1273},[1274,1276,1277,1278],{"id":1180,"depth":115,"text":1275},"Can float() convert an integer string like '10'?",{"id":1197,"depth":115,"text":1198},{"id":1207,"depth":115,"text":1208},{"id":1214,"depth":115,"text":1215},{"id":1221,"depth":82,"text":1222},"Master valueerror could not convert string to float fix in our comprehensive Python beginner guide.","md",{},"\u002Ferrors\u002Fvalueerror-could-not-convert-string-to-float-fix",{"title":5,"description":1280},"errors\u002Fvalueerror-could-not-convert-string-to-float-fix","VFbLKHlrAqK258JJDm3XpXxEcPXZ3qvHBvr7W2A0kP0",1777585498132]