{"id":4699,"date":"2020-09-03T14:35:41","date_gmt":"2020-09-03T09:05:41","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=4699"},"modified":"2020-09-03T14:36:00","modified_gmt":"2020-09-03T09:06:00","slug":"python-abs-function","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/python-abs-function\/","title":{"rendered":"Python abs() Function"},"content":{"rendered":"\n<p>One of the reasons for the popularity of Python is its built-in functions. <a href=\"https:\/\/www.h2kinfosys.com\/courses\/python-online-training\">Python<\/a> provides a large number of<a href=\"https:\/\/docs.python.org\/3\/library\/functions.html\" rel=\"nofollow noopener\" target=\"_blank\"> built-in functions<\/a>. The is an absolute value function to find the Python abs Function of any number. While working with distance calculations we always need a positive number. As distance is always positive. Another example of the usage of absolute values is speed calculations. Let\u2019s take a look at how to use the Python abs Function.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>x = -9<br>print(abs(x))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><em>The output is shown below.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/sTXmjp3OzIRoi9qlRHmIMIe1y5kcxkK_Z-iX1W3gwBf7UEeloTyK3lEiEZHSPKcxlt3jrYPFbclhDzkcMRTJGkzdgWMRT1BeKADzuCTFtfoVzuWlYx9E19vskk5R3NIa0iWMOgz2Du2j7Ocd6w\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Distance example<\/h2>\n\n\n\n<p>The take a look at the distance formula. If we take the absolute value of the difference then we<\/p>\n\n\n\n<p>Don\u2019t need to take the square and then square root.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>point1 = [4, 0]<br>point2 = [6, 6]<br>dist = ((point1[0]-point2[1]))+((point1[0]-point2[1]))print(dist)<br>print(abs(dist))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><em>The output is as follows.<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/N6ySI37qJ4ALW3p9bIwyi5EK_XRjNsZoFFdl6IRcYKldvJ2W7vJ79rpGkjPNUvR_DrursEGFNBr40Wmetuc--DjXjFcPTkuMi_G0WXuPugC5Ey6LZnj34WgfhZb_fWmOJzaSOp6zae4ZRig09A\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Complex number examples<\/h2>\n\n\n\n<p>To find the magnitude of a complex number absolute value function can be used. Let\u2019s take a look at an example.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-subtle-pale-blue-background-color has-background\"><tbody><tr><td>complex_num = 5 &#8211; 5j<br>print(complex_num)<br>print(abs(complex_num))<br><br>complex_num2 = 7 + 4j<br>print(complex_num2)<br>print( abs(complex_num2))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/E8RiuUQdBGuXz1-G4B5VuMepZK-NZ1f8F_9e3mWvKvaEJMJXZJjvYdivybqje90cILAK_4nLzfKz0RfUmf2KQteaGMhGW2MYWxo1wHlmQUF5hVDf2vYRVdChnZOR_Ktja0pyWihbNSR9GMBtQg\" alt=\"\" title=\"\"><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>One of the reasons for the popularity of Python is its built-in functions. Python provides a large number of built-in functions. The is an absolute value function to find the Python abs Function of any number. While working with distance calculations we always need a positive number. As distance is always positive. Another example of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4720,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[500],"tags":[1322,1321],"class_list":["post-4699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science-using-python-tutorials","tag-absolute-value","tag-python-abs-function"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=4699"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/4699\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/4720"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=4699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=4699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=4699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}