{"id":25535904,"date":"2022-07-30T12:04:45","date_gmt":"2022-07-30T06:34:45","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25535904"},"modified":"2022-11-22T14:08:11","modified_gmt":"2022-11-22T08:38:11","slug":"understanding-float-in-python-with-examples","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/","title":{"rendered":"Understanding Float in Python [with Examples]"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e54b31b873a\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e54b31b873a\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#float_Parameters\" >float () Parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#float_Return_Value\" >float () Return Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#Float_Function_Example_1\" >Float () Function Example 1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#Example_How_does_float_work_with_Python\" >Example: How does float () work with Python?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#Converting_an_Integer_to_Float_in_Python\" >Converting an Integer to Float in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#What_is_floatas_integer_ratio\" >What is float.as_integer_ratio()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#What_is_floatis_integer\" >What is float.is_integer()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#What_is_floathex\" >What is float.hex()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#What_is_floatfromhex\" >What is float.fromhex()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<div class=\"detail-banner article-banner-details banner-height\">\n<div class=\"article-info test-class\">\n<h1><\/h1>\n<\/div>\n<\/div>\n<div class=\"info-details\">\n<div id=\"articleLongDescription\">\n<article class=\"desig_author empty-text\">Float() is a method that returns a floating-point number for a provided number or string. Float() returns the value based on the argument or parameter value that is being passed to it. If no value or blank parameter is passed, it will return the values 0.0 as the floating-point output.Python float values are represented as 64-bit double-precision values. 1.8 X 10308 is an approximate maximum value for any floating-point number. If it exceeds or exceeds the max value, Python returns an error with string inf (infinity).<a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25520910 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png\" alt=\"Python and Machine Learning Square\" width=\"345\" height=\"345\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png 345w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-300x300.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-150x150.png 150w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-24x24.png 24w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-48x48.png 48w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-96x96.png 96w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-75x75.png 75w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/a><strong style=\"color: #1d1f20; font-size: 1.953em;\">float () Syntax<\/strong><\/p>\n<article>Every inbuilt function in the python programming language has a predefined objective and a syntax. The term syntax refers to how a particular function needs to be used or called. In the below line, we can learn more about the syntax of the float() function in the python programming language.Syntax: The syntax of the inbuilt float() function: float(X)<\/p>\n<p>Where X is an input parameter passed to the function when it is called in the program.<\/p>\n<h4 style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Learn Coding in your Language! Enroll Here!<\/a><\/strong><\/h4>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"float_Parameters\"><\/span><strong>float () Parameters<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>One of the salient features of the python programming language is that it has rich predefined libraries with numerous methods defined in it. We can use them by just calling the function. While a function is being called, the necessary syntax must be followed and suitable parameters must be passed to the function. Here the term parameters refer to the input arguments given to the method by the user. In the next lines, let us understand more about the parameter of the float() function.<\/p>\n<p>Calling float function: float(X)<\/p>\n<p>Here, the variable X is called the parameter to that function. X can be a normal integer value or any string that has decimal points. An interesting fact about the float() is that the parameter is optional.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_1.png\" alt=\"FloatInPython_1\" width=\"624\" height=\"159\" \/><\/p>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"float_Return_Value\"><\/span><strong>float () Return Value<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Python programming language has many inbuilt libraries and functions. One among them is the float() function. With the help of the float() function, we can convert an input string or an integer value to a floating point value. We already knew that it is not mandatory to send a parameter to the float(), in such a case the function returns 0.0 as output. On another side, the float() function returns the corresponding floating-point value when an integer or string with decimals is given as an input argument. If any input value is out of range of floating value in python, then it returns OverflowError.<\/p>\n<h4 style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/h4>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"Float_Function_Example_1\"><\/span><strong>Float () Function Example 1<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The following is what float() returns for 3 i.e. Integer.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_2.png\" alt=\"FloatInPython_2.\" width=\"624\" height=\"145\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_3.png\" alt=\"\/FloatInPython_3\" width=\"624\" height=\"145\" \/><\/p>\n<p>Example 2: This is what float() returns for 5.5 i.e. decimal.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_4.png\" alt=\"FloatInPython_4\" width=\"624\" height=\"164\" \/><\/p>\n<p>Output<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_5.png\" alt=\"FloatInPython_5.\" width=\"624\" height=\"153\" \/><\/h3>\n<div class=\"engagingBanner\">\n<div class=\"detail-info-banner\" data-reactroot=\"\">\n<div class=\"right-clm\">\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/banners\/free_resources_banners\/lead_banners\/Agile_and_Scrum_.png\" alt=\"FREE Data Science With Python Course\" width=\"16\" height=\"9\" \/><\/p>\n<h4 style=\"text-align: center;\"><\/h4>\n<\/div>\n<\/div>\n<\/div>\n<h3><strong>Examples of float() With String Parameter:<\/strong><\/h3>\n<p>Example 1: This is what float() returns for \u201c5.5\u201d i.e. String.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_6.png\" alt=\"FloatInPython_6\" width=\"624\" height=\"156\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_7.png\" alt=\"FloatInPython_7.\" width=\"624\" height=\"157\" \/><\/p>\n<p>Example 2: This is what float() returns for \u201c5.5\u201d i.e. String with white spaces.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_8.png\" alt=\"FloatInPython_8\" width=\"624\" height=\"157\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_9.png\" alt=\"\/FloatInPython_9.\" width=\"624\" height=\"153\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Example 3: This is what float() returns for \u201c5.500\u201d i.e. String, which is decimal.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_10.png\" alt=\"FloatInPython_10\" width=\"624\" height=\"184\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_11.png\" alt=\"FloatInPython_11\" width=\"624\" height=\"154\" \/><\/p>\n<p>Example 4: This is what float() returns for \u201c-15.5 \\n\u201d i.e. a string, which is a negative decimal.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_12.png\" alt=\"FloatInPython_12\" width=\"624\" height=\"184\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_13.png\" alt=\"FloatInPython_13\" width=\"624\" height=\"141\" \/><\/p>\n<p>Example 5: This is what float() returns for \u201cCucumber\u201d i.e. String, which is not an integer or decimal.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_14.png\" alt=\"FloatInPython_14\" width=\"624\" height=\"163\" \/><\/p>\n<p>Output\u2013float() returns an error, as the string is not an integer or decimal.<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_15.png\" alt=\"FloatInPython_15\" width=\"624\" height=\"150\" \/><\/h3>\n<h4 style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Grab the opportunity to learn Python with Entri! Click Here<\/a><\/strong><\/h4>\n<h3>Examples of float() With Infinity:<\/h3>\n<p>Example 1: This is what float() returns for 1.82e310 i.e. an integer that exceeds the maximum value of the Python floating-point number.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_16.png\" alt=\"FloatInPython_16.\" width=\"624\" height=\"157\" \/><\/p>\n<h4 style=\"text-align: center;\"><\/h4>\n<p>Output<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_17.png\" alt=\"\/FloatInPython_17\" width=\"624\" height=\"151\" \/><\/h3>\n<div class=\"engagingBanner\">\n<div class=\"detail-info-banner\" data-reactroot=\"\">\n<div class=\"right-clm\"><\/div>\n<\/div>\n<\/div>\n<h3><strong>Examples of float() With Not a Number, i.e. NaN as a String.<\/strong><\/h3>\n<p>Example 1: This is what float() returns for \u201cNaN\u201d i.e. String, which is not a number.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_18.png\" alt=\"FloatInPython_18\" width=\"624\" height=\"162\" \/><\/p>\n<p>Output<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_19.png\" alt=\"FloatInPython_19\" width=\"624\" height=\"152\" \/><\/h3>\n<h4 style=\"text-align: center;\"><\/h4>\n<h3><strong>Examples of float() With Infinity, i.e. Infinity as a String.<\/strong><\/h3>\n<p>Example 1: This is what float() returns for \u201cInfinity\u201d i.e. String.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_20.png\" alt=\"FloatInPython_20.\" width=\"624\" height=\"182\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_21.png\" alt=\"FloatInPython_21\" width=\"624\" height=\"152\" \/><\/p>\n<p>Example 2: This is what float() returns for \u201cinf\u201d i.e. String.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_22.png\" alt=\"FloatInPython_22.\" width=\"624\" height=\"148\" \/><\/p>\n<p>Output<\/p>\n<h3><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_23.png\" alt=\"FloatInPython_23\" width=\"624\" height=\"152\" \/><\/h3>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"Example_How_does_float_work_with_Python\"><\/span><strong>Example: How does float () work with Python?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>With this example, let us get a clearer understanding of the float() in the python programming language.<\/p>\n<p>Snippet 1: print(float())<\/p>\n<p>Output 1: 0.0<\/p>\n<p>Snippet 2: print(float(17))<\/p>\n<p>Output 2: 17.0<\/p>\n<p>Snippet 3: print(float(10.02))<\/p>\n<p>Output 3: 10.02<\/p>\n<p>Snippet 4: print(float(&#8216;podium&#8217;))<\/p>\n<p>Output 4: ValueError: could not convert string to float: &#8216;podium&#8217;<\/p>\n<p>Snippet 5: print(float(-8))<\/p>\n<p>Output 5: -8.0<\/p>\n<p>Snippet 6: print(float(&#8216;1234&#8217;))<\/p>\n<p>Output 6: 1234.0<\/p>\n<p>Snippet 7: print(float(123456789123499999991111111111111111111122255555555555555555555555555555555555555555555550000000000000000000011111111111111111111111111111111111111111111111188888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888555555555555555555555555555555555555555555555555555555555555555555555555555555522222222222222222222222222222222222222222))<\/p>\n<p>Output 7: OverflowError: int too large to convert to float<\/p>\n<h4 style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Grab the opportunity to learn Python with Entri! Click Here<\/a><\/strong><\/h4>\n<h3><strong>Example: float() for infinity and NaN (Not a Number)?<\/strong><\/h3>\n<p>With this example, let us get a clearer understanding of the float() function in the programming language when infinity and NaN (Not a Number) values are given as input parameters to the float() function.<\/p>\n<p>Snippet 8: print(float(&#8220;nan&#8221;))<\/p>\n<p>Output 8: nan<\/p>\n<p>Snippet 9: print(float(&#8220;NaN&#8221;))<\/p>\n<p>Output 9: nan<\/p>\n<p>Snippet 10: print(float(&#8220;inf&#8221;))<\/p>\n<p>Output 10: inf<\/p>\n<p>Snippet 11: print(float(&#8220;InF&#8221;))<\/p>\n<p>Output 11: inf<\/p>\n<p>Snippet 12: print(float(&#8220;InFiNiTy&#8221;))<\/p>\n<p>Output 12: inf<\/p>\n<p>Snippet 13: print(float(&#8220;infinity&#8221;))<\/p>\n<p>Output 13: inf<\/p>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"Converting_an_Integer_to_Float_in_Python\"><\/span><strong>Converting an Integer to Float in Python<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>As we discussed earlier, we can pass an integer value to the float() function as an input argument and get its equivalent floating point value as output. Let us understand this with the help of an example.<\/p>\n<p>Snippet 14: print(float(23))<\/p>\n<p>Output 14: 23.0<\/p>\n<p>Snippet 15: print(float(112000))<\/p>\n<p>Output 15: print(float(112000))<\/p>\n<p><strong style=\"font-size: 1.953em;\">Converting a String <\/strong><strong style=\"font-size: 1.953em;\">to Float in Python<\/strong><\/p>\n<\/article>\n<article>As we discussed earlier, we can pass a string value to the float() function as an input argument and get its equivalent floating point value as output (given condition is that the string must be numerical). Let us understand this with the help of an example.Snippet 16: print(float(&#8216;python&#8217;))<\/p>\n<p>Output 16: ValueError: could not convert string to float: &#8216;python&#8217;<\/p>\n<p>Snippet 17: print(float(&#8217;64&#8217;))<\/p>\n<p>Output 17: 64.0<\/p>\n<h3><strong>Additional Methods That Are Available In Float():<\/strong><\/h3>\n<p>Float() also has some additional methods that are useful to identify finite integers, decimal from hexadecimal strings, etc. To understand this better, it makes sense to see it in-detail with examples.<\/p>\n<h4 style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Grab the opportunity to learn Python with Entri! Click Here<\/a><\/strong><\/h4>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"What_is_floatas_integer_ratio\"><\/span><strong>What is float.as_integer_ratio()?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Float.as_integer_ratio() is a built-in function that provides a pair of integers whose ratio is equivalent to the original float provided.<\/p>\n<p>Syntax: float.as_integer_ratio()<\/p>\n<p>return Tupple (integer pair)<\/p>\n<p>Example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_24.png\" alt=\"FloatInPython_24\" width=\"624\" height=\"194\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_25.png\" alt=\"\/FloatInPython_25.\" width=\"512\" height=\"123\" \/><\/p>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"What_is_floatis_integer\"><\/span><strong>What is float.is_integer()?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>float.is_integer() is used to identify whether the given float instance is a finite integer or not. If it is finite, the integer returns true, else it returns false.<\/p>\n<p>Example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_26.png\" alt=\"FloatInPython_26.\" width=\"624\" height=\"176\" \/><\/p>\n<p>Output<\/p>\n<\/article>\n<article>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_27.png\" alt=\"FloatInPython_27.\" width=\"624\" height=\"155\" \/><\/h2>\n<\/article>\n<article>\n<h4 style=\"text-align: center;\"><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><strong>Learn to code from industry experts! Enroll here<\/strong><\/a><\/h4>\n<h2><span class=\"ez-toc-section\" id=\"What_is_floathex\"><\/span><strong>What is float.hex()?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>float.hex() returns the hexadecimal string for the given floating number.<\/p>\n<p>Example<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_28.png\" alt=\"FloatInPython_28.\" width=\"624\" height=\"186\" \/><\/p>\n<p>Output<\/p>\n<\/article>\n<article>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_29.png\" alt=\"FloatInPython_29\" width=\"624\" height=\"155\" \/><\/h2>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"What_is_floatfromhex\"><\/span><strong>What is float.fromhex()?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>float.fromhex() returns the floating-point number which represents the given hexadecimal string.<\/p>\n<p>Example:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_30.png\" alt=\"\/FloatInPython_30\" width=\"624\" height=\"200\" \/><\/p>\n<p>Output<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"blend-mode\" src=\"https:\/\/www.simplilearn.com\/ice9\/free_resources_article_thumb\/FloatInPython_31.png\" alt=\"FloatInPython_31\" width=\"624\" height=\"153\" \/><\/p>\n<\/article>\n<article>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Float() in python is an important method that is useful to represent floating-point numbers. It is used to represent real numbers and is written with the decimals dividing the integer and fractional parts.<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25520910 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png\" alt=\"Python and Machine Learning Square\" width=\"345\" height=\"345\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square.png 345w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-300x300.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-150x150.png 150w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-24x24.png 24w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-48x48.png 48w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-96x96.png 96w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Square-75x75.png 75w\" sizes=\"auto, (max-width: 345px) 100vw, 345px\" \/><\/a><\/p>\n<p>In this article, you have learned what float() is, the syntax for float(), and additional float() methods along with good working examples. You also saw how to define float(), how to print, as well as get the output from a float, etc.<\/p>\n<\/article>\n<\/article>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Float() is a method that returns a floating-point number for a provided number or string. Float() returns the value based on the argument or parameter value that is being passed to it. If no value or blank parameter is passed, it will return the values 0.0 as the floating-point output.Python float values are represented as [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":25536055,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1888],"tags":[],"class_list":["post-25535904","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-python-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Understanding Float in Python [with Examples] - Entri Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Understanding Float in Python [with Examples] - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"Float() is a method that returns a floating-point number for a provided number or string. Float() returns the value based on the argument or parameter value that is being passed to it. If no value or blank parameter is passed, it will return the values 0.0 as the floating-point output.Python float values are represented as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/entri.me\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-30T06:34:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-22T08:38:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"615\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Feeba Mahin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@entri_app\" \/>\n<meta name=\"twitter:site\" content=\"@entri_app\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Feeba Mahin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/\"},\"author\":{\"name\":\"Feeba Mahin\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\"},\"headline\":\"Understanding Float in Python [with Examples]\",\"datePublished\":\"2022-07-30T06:34:45+00:00\",\"dateModified\":\"2022-11-22T08:38:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/\"},\"wordCount\":1172,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png\",\"articleSection\":[\"Articles\",\"Python Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/\",\"url\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/\",\"name\":\"Understanding Float in Python [with Examples] - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png\",\"datePublished\":\"2022-07-30T06:34:45+00:00\",\"dateModified\":\"2022-11-22T08:38:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png\",\"width\":820,\"height\":615,\"caption\":\"Understanding Float in Python [with Examples]\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Programming\",\"item\":\"https:\/\/entri.app\/blog\/category\/python-programming\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Understanding Float in Python [with Examples]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/blog\/#website\",\"url\":\"https:\/\/entri.app\/blog\/\",\"name\":\"Entri Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/blog\/#organization\",\"name\":\"Entri App\",\"url\":\"https:\/\/entri.app\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png\",\"width\":989,\"height\":446,\"caption\":\"Entri App\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/entri.me\/\",\"https:\/\/x.com\/entri_app\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\",\"name\":\"Feeba Mahin\",\"url\":\"https:\/\/entri.app\/blog\/author\/feeba123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Understanding Float in Python [with Examples] - Entri Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/","og_locale":"en_US","og_type":"article","og_title":"Understanding Float in Python [with Examples] - Entri Blog","og_description":"Float() is a method that returns a floating-point number for a provided number or string. Float() returns the value based on the argument or parameter value that is being passed to it. If no value or blank parameter is passed, it will return the values 0.0 as the floating-point output.Python float values are represented as [&hellip;]","og_url":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-07-30T06:34:45+00:00","article_modified_time":"2022-11-22T08:38:11+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png","type":"image\/png"}],"author":"Feeba Mahin","twitter_card":"summary_large_image","twitter_creator":"@entri_app","twitter_site":"@entri_app","twitter_misc":{"Written by":"Feeba Mahin","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/"},"author":{"name":"Feeba Mahin","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36"},"headline":"Understanding Float in Python [with Examples]","datePublished":"2022-07-30T06:34:45+00:00","dateModified":"2022-11-22T08:38:11+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/"},"wordCount":1172,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png","articleSection":["Articles","Python Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/","url":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/","name":"Understanding Float in Python [with Examples] - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png","datePublished":"2022-07-30T06:34:45+00:00","dateModified":"2022-11-22T08:38:11+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/07\/Understanding-Float-in-Python-with-Examples.png","width":820,"height":615,"caption":"Understanding Float in Python [with Examples]"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/understanding-float-in-python-with-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Programming","item":"https:\/\/entri.app\/blog\/category\/python-programming\/"},{"@type":"ListItem","position":3,"name":"Understanding Float in Python [with Examples]"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/blog\/#website","url":"https:\/\/entri.app\/blog\/","name":"Entri Blog","description":"","publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/blog\/#organization","name":"Entri App","url":"https:\/\/entri.app\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2019\/10\/Entri-Logo-1.png","width":989,"height":446,"caption":"Entri App"},"image":{"@id":"https:\/\/entri.app\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/entri.me\/","https:\/\/x.com\/entri_app"]},{"@type":"Person","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36","name":"Feeba Mahin","url":"https:\/\/entri.app\/blog\/author\/feeba123\/"}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25535904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/comments?post=25535904"}],"version-history":[{"count":8,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25535904\/revisions"}],"predecessor-version":[{"id":25547690,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25535904\/revisions\/25547690"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25536055"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25535904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25535904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25535904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}