{"id":25526480,"date":"2022-06-05T16:14:27","date_gmt":"2022-06-05T10:44:27","guid":{"rendered":"https:\/\/entri.app\/blog\/?p=25526480"},"modified":"2022-11-22T16:54:42","modified_gmt":"2022-11-22T11:24:42","slug":"python-in-built-functions-you-should-know","status":"publish","type":"post","link":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/","title":{"rendered":"Python In-Built Functions You Should Know"},"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-69cff6a0edde1\" 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-69cff6a0edde1\"  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\/python-in-built-functions-you-should-know\/#1_reduce\" >1. reduce()<\/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\/python-in-built-functions-you-should-know\/#2_split\" >2. split()<\/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\/python-in-built-functions-you-should-know\/#3_enumerate\" >3. enumerate()<\/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\/python-in-built-functions-you-should-know\/#4_eval\" >4. eval()<\/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\/python-in-built-functions-you-should-know\/#5_round\" >5. round()<\/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\/python-in-built-functions-you-should-know\/#6_max\" >6. max()<\/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\/python-in-built-functions-you-should-know\/#7_min\" >7. min()<\/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\/python-in-built-functions-you-should-know\/#8_map\" >8. map()<\/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\/python-in-built-functions-you-should-know\/#9_getattr\" >9. getattr()<\/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\/python-in-built-functions-you-should-know\/#10_append\" >10. append()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#11_range\" >11. range()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#12_slice\" >12. slice()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#13_format\" >13. format()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#14_strip\" >14. strip()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#15_abs\" >15. abs()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#_16_upper\" >\u00a016. upper()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#17_lower\" >17. lower()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#18_sorted\" >18. sorted()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#19_join\" >19. join()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#20_replace\" >20. replace()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#21_bin\" >21. bin()<\/a><\/li><\/ul><\/nav><\/div>\n<div>\n<div class=\"article-title\"><\/div>\n<div class=\"article-buttons\">\n<div class=\"article--viewer_like tooltip\"><\/div>\n<\/div>\n<\/div>\n<div class=\"text\">\n<p>Python is one of the most lucrative programming languages. According to research, there were approximately\u00a010 million Python developers\u00a0in 2020 worldwide and the count is increasing day by day. It provides ease in building a number of applications, web development processes, and a lot more. When it comes to making a program short and clear, we use in-built functions which are a set of statements collectively performing a task. Using in-built functions in a program makes it beneficial in many ways such as:<\/p>\n<ul>\n<li><i>Makes it less complex.<\/i><\/li>\n<li><i>Enhances readability.<\/i><\/li>\n<li><i>Reduces coding time and debugging time.<\/i><\/li>\n<li><i>Allows re-usage of code.<\/i><\/li>\n<\/ul>\n<p>Hence, it plays a major role in the development of an application.<\/p>\n<\/div>\n<p>Below are a list of valuable built-in Python functions and methods that shorten your code and improve its efficiency.<\/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<div id=\"adsninja-ad-zone-div-gpt-ad-1619031514790-NIC\" class=\"adsninja-ad-zone\">\n<div id=\"dynamically-injected-refresh-ad-zone-div-gpt-ad-1619031514790-NIC\" class=\"dynamically-injected-refresh-ad-zone\" data-original-ad-element-id=\"div-gpt-ad-1619031514790-NIC\" data-current-ad-element-id=\"div-gpt-ad-1619031514790-NIC\" data-refresh-count=\"1\" data-floating-allowed=\"true\" data-refreshing-allowed=\"true\" data-next-ad-element-id=\"div-gpt-ad-1619031514790-NIC-count-1\">\n<div class=\"ad-current\">\n<div id=\"ad-zone-container-div-gpt-ad-1619031514790-NIC\" class=\"ad-zone-container ad-zone-container-content-native-in-content ad-loaded\" data-no-fill-collapsable=\"false\">\n<div id=\"ad-zone-size-container-div-gpt-ad-1619031514790-NIC\" class=\"ad-zone-size-container ad-zone-size-container-content-native-in-content\">\n<div class=\"ad-zone ad-zone-content-native-in-content\">\n<div class=\"ad-zone-inline ad-zone-inline-content-native-in-content\">\n<div id=\"div-gpt-ad-1619031514790-NIC\" data-google-query-id=\"CK6prr3ojvgCFfuwJwIdZwgOVw\">\n<div id=\"google_ads_iframe_\/39363775\/MUO_BelowMainPic_728x90_Desktop_0__container__\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2 id=\"reduce\"><span class=\"ez-toc-section\" id=\"1_reduce\"><\/span>1. reduce()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Python&#8217;s\u00a0<strong>reduce()<\/strong> function repeats over each item in a list, or any other iterable data type, and returns a single value. It is one of the methods of the built-in<strong>\u00a0functools<\/strong>\u00a0class of Python.<\/p>\n<p>Lets see an example of how to use reduce:<\/p>\n<pre><code class=\"hljs javascript\"><span class=\"hljs-keyword\">from<\/span> functools <span class=\"hljs-keyword\">import<\/span> reduce\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">add_num<\/span><span class=\"hljs-params\">(a, b)<\/span>:<\/span>\r\n   <span class=\"hljs-keyword\">return<\/span> a+b\r\na = [1, 2, 3, 10]\r\n<span class=\"hljs-keyword\">print<\/span>(reduce(add_num, a))\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output: <span class=\"hljs-tag\">strong<\/span>&gt;16<\/code><\/pre>\n<p>You can also format a list of strings using the\u00a0<strong>reduce()<\/strong>\u00a0function:<\/p>\n<pre><code class=\"hljs xml\"><span class=\"hljs-keyword\">from<\/span> functools <span class=\"hljs-keyword\">import<\/span> reduce\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">add_str<\/span><span class=\"hljs-params\">(a,b)<\/span>:<\/span>\r\n\treturn a+<span class=\"hljs-symbol\">'<\/span> <span class=\"hljs-symbol\">'<\/span>+b\r\na = [<span class=\"hljs-symbol\">'<\/span>MUO<span class=\"hljs-symbol\">'<\/span>, <span class=\"hljs-symbol\">'<\/span>is<span class=\"hljs-symbol\">'<\/span>, <span class=\"hljs-symbol\">'<\/span>a<span class=\"hljs-symbol\">'<\/span>, <span class=\"hljs-symbol\">'<\/span>media<span class=\"hljs-symbol\">'<\/span>, <span class=\"hljs-symbol\">'<\/span>website<span class=\"hljs-symbol\">'<\/span>]\r\n<span class=\"hljs-keyword\">print<\/span>(reduce(add_str, a))\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; MUO is a media website <\/code><\/pre>\n<div id=\"adsninja-ad-zone-MUO-Reg-Org\" class=\"adsninja-ad-zone\">\n<div id=\"dynamically-injected-refresh-ad-zone-MUO-Reg-Org\" class=\"dynamically-injected-refresh-ad-zone\">\n<div class=\"ad-current\">\n<div id=\"ad-zone-container-MUO-Reg-Org\" class=\"ad-zone-container ad-zone-container-content-character-count-repeatable-1\" data-no-fill-collapsable=\"false\">\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\">Learn Coding in your Language! Enroll Here!<\/a><\/strong><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h2 id=\"split\"><span class=\"ez-toc-section\" id=\"2_split\"><\/span>2. split()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0<strong>split()<\/strong>\u00a0function breaks a string based on set criteria. You can use it to split a string value from a web form. Or you can even use it to count the number of words in a piece of text.<\/p>\n<p>The example code below splits a list wherever there&#8217;s a space:<\/p>\n<pre><code class=\"hljs xml\">words = <span class=\"hljs-symbol\">\"<\/span>column1 column2 column3<span class=\"hljs-symbol\">\"<\/span>\r\nwords = words.split(<span class=\"hljs-symbol\">\"<\/span> <span class=\"hljs-symbol\">\"<\/span>)\r\n<span class=\"hljs-keyword\">print<\/span>(words)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; [<span class=\"hljs-symbol\">'<\/span>column1<span class=\"hljs-symbol\">'<\/span>, <span class=\"hljs-symbol\">'<\/span>column2<span class=\"hljs-symbol\">'<\/span>, <span class=\"hljs-symbol\">'<\/span>column3<span class=\"hljs-symbol\">'<\/span>]<\/code><\/pre>\n<h2 id=\"enumerate\"><span class=\"ez-toc-section\" id=\"3_enumerate\"><\/span>3. enumerate()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0<strong>enumerate()<\/strong>\u00a0function returns the length of an iterable and loops through its items simultaneously. Thus, while printing each item in an iterable data type, it simultaneously outputs its index.<\/p>\n<p>Let us suppose that you want a user to see the list of items available in your database. You can pass them into a list and use the <strong>enumerate()<\/strong>\u00a0function to return this as a numbered list.<\/p>\n<p>Here&#8217;s how you can achieve this using the\u00a0<strong>enumerate()<\/strong>\u00a0method:<\/p>\n<pre><code class=\"hljs xml\">fruits = [<span class=\"hljs-symbol\">\"<\/span>grape<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>apple<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>mango<span class=\"hljs-symbol\">\"<\/span>]\r\nfor i, j in enumerate(fruit+++++++++++++++s):\r\n\t<span class=\"hljs-keyword\">print<\/span>(i, j)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; \r\n0 grape\r\n1 apple\r\n2 mango<\/code><\/pre>\n<div id=\"adsninja-ad-zone-div-gpt-ad-1494450502098-ccr3\" class=\"adsninja-ad-zone\">\n<div id=\"dynamically-injected-refresh-ad-zone-div-gpt-ad-1494450502098-ccr3\" class=\"dynamically-injected-refresh-ad-zone\" data-original-ad-element-id=\"div-gpt-ad-1494450502098-ccr3\" data-current-ad-element-id=\"div-gpt-ad-1494450502098-ccr3\" data-refresh-count=\"0\" data-floating-allowed=\"true\" data-refreshing-allowed=\"true\">\n<div class=\"ad-current\">\n<div id=\"ad-zone-container-div-gpt-ad-1494450502098-ccr3\" class=\"ad-zone-container ad-zone-container-content-character-count-repeatable-3 ad-loaded\" data-no-fill-collapsable=\"false\">\n<div id=\"ad-zone-size-container-div-gpt-ad-1494450502098-ccr3\" class=\"ad-zone-size-container ad-zone-size-container-content-character-count-repeatable-3\">\n<div class=\"ad-zone ad-zone-content-character-count-repeatable-3\">\n<div class=\"ad-zone-inline ad-zone-inline-content-character-count-repeatable-3\">\n<div id=\"div-gpt-ad-1494450502098-ccr3\" data-google-query-id=\"COnKxL7ojvgCFXSxJwIdqbQKXQ\">\n<div id=\"google_ads_iframe_\/39363775\/MUO_Injected3_300X250_Desktop_2__container__\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>Whereas, you might&#8217;ve wasted valuable time using the following method to achieve this:<\/p>\n<pre><code class=\"hljs xml\">fruits = [<span class=\"hljs-symbol\">\"<\/span>grape<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>apple<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>mango<span class=\"hljs-symbol\">\"<\/span>]\r\nfor i in range(len(fruits)):\r\n\t<span class=\"hljs-keyword\">print<\/span>(i, fruits[i])<\/code><\/pre>\n<p>In addition to being faster, enumerating the list lets you customize how your numbered items come through.<\/p>\n<p>In essence, you can decide to start numbering from one instead of zero, by including a\u00a0<strong>start<\/strong>\u00a0parameter:<\/p>\n<div id=\"adsninja-ad-zone-div-gpt-ad-1494450502098-ccr4\" class=\"adsninja-ad-zone\">\n<div id=\"dynamically-injected-refresh-ad-zone-div-gpt-ad-1494450502098-ccr4\" class=\"dynamically-injected-refresh-ad-zone\" data-original-ad-element-id=\"div-gpt-ad-1494450502098-ccr4\" data-current-ad-element-id=\"div-gpt-ad-1494450502098-ccr4\" data-refresh-count=\"1\" data-floating-allowed=\"true\" data-refreshing-allowed=\"true\" data-next-ad-element-id=\"div-gpt-ad-1494450502098-ccr4-count-1\">\n<div class=\"ad-current\">\n<div id=\"ad-zone-container-div-gpt-ad-1494450502098-ccr4\" class=\"ad-zone-container ad-zone-container-content-character-count-repeatable-4 ad-loaded\" data-no-fill-collapsable=\"false\">\n<div id=\"ad-zone-size-container-div-gpt-ad-1494450502098-ccr4\" class=\"ad-zone-size-container ad-zone-size-container-content-character-count-repeatable-4\">\n<div class=\"ad-zone ad-zone-content-character-count-repeatable-4\">\n<div class=\"ad-zone-inline ad-zone-inline-content-character-count-repeatable-4\">\n<div id=\"div-gpt-ad-1494450502098-ccr4\" data-google-query-id=\"COOzsL3ojvgCFTScJwIdMFwBgg\">\n<div id=\"google_ads_iframe_\/39363775\/MUO_Injected3_300X250_Desktop_3__container__\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<pre><code class=\"hljs xml\">for i, j in enumerate(fruits, <span class=\"hljs-keyword\">start<\/span>=<span class=\"hljs-number\">1<\/span>):\r\n\t<span class=\"hljs-keyword\">print<\/span>(i, j)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; \r\n1 grape\r\n2 apple\r\n3 mango<\/code><\/pre>\n<h2 id=\"eval\"><span class=\"ez-toc-section\" id=\"4_eval\"><\/span>4. eval()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Python&#8217;s\u00a0<strong>eval()<\/strong> function perform mathematical operations on integers or floats, even in their string forms. It&#8217;s often helpful if a mathematical calculation is in a string format.<\/p>\n<p>Here&#8217;s how it works:<\/p>\n<pre><code class=\"hljs xml\">g = <span class=\"hljs-symbol\">\"<\/span>(4 * 5)\/4<span class=\"hljs-symbol\">\"<\/span>\r\nd = <span class=\"hljs-built_in\">eval<\/span>(g)\r\n<span class=\"hljs-keyword\">print<\/span>(d)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; 5.0<\/code><\/pre>\n<h2 id=\"round\"><span class=\"ez-toc-section\" id=\"5_round\"><\/span>5. round()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can round up the result of a mathematical operation to a specific number of significant figures using\u00a0<strong>round()<\/strong>:<\/p>\n<pre><code class=\"hljs xml\">raw_average = (4+5+7\/3)\r\nrounded_average=round(raw_average, 2)\r\nprint(\"The raw average <span class=\"hljs-keyword\">is<\/span>:\", raw_average)\r\nprint(\"The rounded average <span class=\"hljs-keyword\">is<\/span>:\", rounded_average)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; \r\nThe raw average <span class=\"hljs-keyword\">is<\/span>: <span class=\"hljs-number\">11.333333333333334<\/span>\r\nThe rounded average <span class=\"hljs-keyword\">is<\/span>: <span class=\"hljs-number\">11.33<\/span><\/code><\/pre>\n<h2 id=\"max\"><span class=\"ez-toc-section\" id=\"6_max\"><\/span>6. max()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0<strong>max()<\/strong> function returns the highest ranked item in an iterable. You should be careful not to confuse this with the most frequently occurring value, though.<\/p>\n<p>Let&#8217;s print the highest ranked value in the dictionary below using the\u00a0<strong>max()<\/strong>\u00a0function:<\/p>\n<pre><code class=\"hljs xml\">b = {1:<span class=\"hljs-symbol\">\"<\/span>grape<span class=\"hljs-symbol\">\"<\/span>, 2:<span class=\"hljs-symbol\">\"<\/span>apple<span class=\"hljs-symbol\">\"<\/span>, 3:<span class=\"hljs-symbol\">\"<\/span>applesss<span class=\"hljs-symbol\">\"<\/span>, 4:<span class=\"hljs-symbol\">\"<\/span>zebra<span class=\"hljs-symbol\">\"<\/span>, 5:<span class=\"hljs-symbol\">\"<\/span>mango<span class=\"hljs-symbol\">\"<\/span>}\r\n<span class=\"hljs-keyword\">print<\/span>(max(b.values()))\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; zebra<\/code><\/pre>\n<p>The code above ranks the items in the dictionary alphabetically and prints the last one.<\/p>\n<p>Now use the\u00a0<strong>max()<\/strong>\u00a0function to see the largest integer in a list:<\/p>\n<pre><code class=\"hljs xml\">a = [1, 65, 7, 9]\r\n<span class=\"hljs-keyword\">print<\/span>(max(a))\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; 65<\/code><\/pre>\n<h2 id=\"min\"><span class=\"ez-toc-section\" id=\"7_min\"><\/span>7. min()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0<strong>min()<\/strong>\u00a0function does the opposite of what\u00a0<strong>max()<\/strong>\u00a0does:<\/p>\n<pre><code class=\"hljs xml\">fruits = [<span class=\"hljs-symbol\">\"<\/span>grape<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>apple<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>applesss<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>zebra<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>mango<span class=\"hljs-symbol\">\"<\/span>]\r\nb = {1:<span class=\"hljs-symbol\">\"<\/span>grape<span class=\"hljs-symbol\">\"<\/span>, 2:<span class=\"hljs-symbol\">\"<\/span>apple<span class=\"hljs-symbol\">\"<\/span>, 3:<span class=\"hljs-symbol\">\"<\/span>applesss<span class=\"hljs-symbol\">\"<\/span>, 4:<span class=\"hljs-symbol\">\"<\/span>zebra<span class=\"hljs-symbol\">\"<\/span>, 5:<span class=\"hljs-symbol\">\"<\/span>mango<span class=\"hljs-symbol\">\"<\/span>}\r\na = [1, 65, 7, 9]\r\n<span class=\"hljs-keyword\">print<\/span>(min(a))\r\n<span class=\"hljs-keyword\">print<\/span>(min(b.values()))\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; \r\n1\r\napple<\/code><\/pre>\n<h2 id=\"map\"><span class=\"ez-toc-section\" id=\"8_map\"><\/span>8. map()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Like\u00a0<strong>reduce()<\/strong>, the\u00a0<strong>map()<\/strong>\u00a0function lets you iterate over each item in an iterable. However, instead of producing a single result,\u00a0<strong>map()<\/strong>\u00a0operates on each item independently.<\/p>\n<p>Ultimately, you can perform mathematical operations on two or more lists using the\u00a0<strong>map()<\/strong>\u00a0function. You can even use it to manipulate an array containing any data type.<\/p>\n<p>Here&#8217;s how to find the combined sum of two lists containing integers using the\u00a0<strong>map()<\/strong>\u00a0function:<\/p>\n<pre><code class=\"hljs php\">b = [1, 3, 4, 6]\r\na = [1, 65, 7, 9]\r\n<strong><span class=\"hljs-comment\"># Declare a separate function to handle the addition:<\/span><\/strong> \r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">add<\/span><span class=\"hljs-params\">(a, b)<\/span>:<\/span>\r\n\t<span class=\"hljs-keyword\">return<\/span> a+b\r\n<strong><span class=\"hljs-comment\"># Pass the function and the two lists into the built-in map() function:<\/span><\/strong> \r\na = sum(map(add, b, a))\r\n<span class=\"hljs-keyword\">print<\/span>(a) \r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; 96<\/code><\/pre>\n<h2 id=\"getattr\"><span class=\"ez-toc-section\" id=\"9_getattr\"><\/span>9. getattr()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Python&#8217;s\u00a0<strong>getattr()<\/strong>\u00a0returns the attribute of an object. It accepts two parameters: the class and the target attribute name.<\/p>\n<p>Here&#8217;s an example:<\/p>\n<pre><code class=\"hljs python\"><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">ty<\/span>:<\/span>\r\n\t<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">__init__<\/span><span class=\"hljs-params\">(self, number, name)<\/span>:<\/span>\r\n\t\t<span class=\"hljs-keyword\">self<\/span>.number = number\r\n\t\t<span class=\"hljs-keyword\">self<\/span>.name = name\r\na = ty(5*8, <span class=\"hljs-symbol\">\"<\/span>Idowu<span class=\"hljs-symbol\">\"<\/span>)\r\nb = getattr(a, <span class=\"hljs-symbol\">'<\/span>name<span class=\"hljs-symbol\">'<\/span>)\r\n<span class=\"hljs-keyword\">print<\/span>(b)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt;Idowu<\/code><\/pre>\n<p 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><\/p>\n<h2 id=\"append\"><span class=\"ez-toc-section\" id=\"10_append\"><\/span>10. append()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Whether you are excavating into web development or machine learning with Python, <strong>append()<\/strong> is another Python method you&#8217;ll often need. It works by writing new data into a list without overwriting its original content.<\/p>\n<p>The example below multiplies each item in a range of integers by three and writes them into an existing list:<\/p>\n<pre><code class=\"hljs xml\">nums = [1, 2, 3]\r\nappendedlist = [2, 4]\r\nfor i in nums:\r\n\ta = i*3\r\n\t<span class=\"hljs-selector-tag\">appendedlist<\/span><span class=\"hljs-selector-class\">.append<\/span>(<span class=\"hljs-selector-tag\">a<\/span>)\r\n<span class=\"hljs-keyword\">print<\/span>(appendedlist)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt;[2, 4, 3, 6, 9]<\/code><\/pre>\n<h2 id=\"range\"><span class=\"ez-toc-section\" id=\"11_range\"><\/span>11. range()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You might already be familiar with\u00a0<strong>range()<\/strong>\u00a0in Python. It&#8217;s handy if you want to create a list of integers ranging between specific numbers without explicitly writing them out.<\/p>\n<p>Let&#8217;s create a list of the odd numbers between one and five using this function:<\/p>\n<pre><code class=\"hljs xml\">a = range(1, 6)\r\nb = []\r\nfor i in a:\r\n\tif i%2!=0:\r\n\t\t<span class=\"hljs-selector-tag\">b<\/span><span class=\"hljs-selector-class\">.append<\/span>(<span class=\"hljs-selector-tag\">i<\/span>)\r\n<span class=\"hljs-keyword\">print<\/span>(b)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; [1, 3, 5]<\/code><\/pre>\n<h2 id=\"slice\"><span class=\"ez-toc-section\" id=\"12_slice\"><\/span>12. slice()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Although the\u00a0<strong>slice()<\/strong>\u00a0function and the traditional slice method give similar outputs, using\u00a0<strong>slice()<\/strong>\u00a0in your code can make it more readable.<\/p>\n<p>You can slice any mutable iterable using the slice method:<\/p>\n<pre><code class=\"hljs xml\">b = [1, 3, 4, 6, 7, 10]\r\nst = <span class=\"hljs-symbol\">\"<\/span>Python tutorial<span class=\"hljs-symbol\">\"<\/span>\r\nsliceportion = slice(0, 4)\r\n<span class=\"hljs-keyword\">print<\/span>(b[sliceportion])\r\n<span class=\"hljs-keyword\">print<\/span>(st[sliceportion])\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; \r\n<span class=\"hljs-selector-attr\">[1, 3, 4, 6]<\/span>\r\nPyth<\/code><\/pre>\n<p>The above code gives a similar output when you use the traditional method below:<\/p>\n<pre><code class=\"hljs css\"><span class=\"hljs-keyword\">print<\/span>(b[<span class=\"hljs-number\">0<\/span>:<span class=\"hljs-number\">4<\/span>])\r\n<span class=\"hljs-keyword\">print<\/span>(st[<span class=\"hljs-number\">0<\/span>:<span class=\"hljs-number\">4<\/span>])<\/code><\/pre>\n<h2 id=\"format\"><span class=\"ez-toc-section\" id=\"13_format\"><\/span>13. format()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0<strong>format()<\/strong> method helps you to manipulate your string output. Here&#8217;s how it works:<\/p>\n<div id=\"adsninja-ad-zone-div-gpt-ad-1494450502098-ccr-REPEAT11\" class=\"adsninja-ad-zone\">\n<div id=\"dynamically-injected-refresh-ad-zone-div-gpt-ad-1494450502098-ccr-REPEAT11\" class=\"dynamically-injected-refresh-ad-zone\" data-original-ad-element-id=\"div-gpt-ad-1494450502098-ccr-REPEAT11\" data-current-ad-element-id=\"div-gpt-ad-1494450502098-ccr-REPEAT11\" data-refresh-count=\"0\" data-floating-allowed=\"true\" data-refreshing-allowed=\"true\">\n<div class=\"ad-current\">\n<div id=\"ad-zone-container-div-gpt-ad-1494450502098-ccr-REPEAT11\" class=\"ad-zone-container ad-zone-container-content-character-count-repeatable ad-loaded\" data-no-fill-collapsable=\"false\">\n<div id=\"ad-zone-size-container-div-gpt-ad-1494450502098-ccr-REPEAT11\" class=\"ad-zone-size-container ad-zone-size-container-content-character-count-repeatable\">\n<div class=\"ad-zone ad-zone-content-character-count-repeatable\">\n<div class=\"ad-zone-inline ad-zone-inline-content-character-count-repeatable\">\n<div id=\"div-gpt-ad-1494450502098-ccr-REPEAT11\" data-google-query-id=\"CPOhir7ojvgCFT6bJwIdNvIHaQ\">\n<div id=\"google_ads_iframe_\/39363775\/MUO_Injected3_300X250_Desktop_10__container__\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<pre><code class=\"hljs xml\">multiple = 5*2\r\nmultiple2 = 7*2\r\na =  \"{} <span class=\"hljs-keyword\">is<\/span> the multiple of <span class=\"hljs-number\">5<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">2<\/span>, but {} <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-number\">7<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">2<\/span>\"\r\na = a.format(multiple, multiple2)\r\n<span class=\"hljs-keyword\">print<\/span>(a)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; \r\n<span class=\"hljs-number\">10<\/span> <span class=\"hljs-keyword\">is<\/span> the multiple of <span class=\"hljs-number\">5<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">2<\/span>, but <span class=\"hljs-number\">14<\/span> <span class=\"hljs-keyword\">is<\/span> <span class=\"hljs-keyword\">for<\/span> <span class=\"hljs-number\">7<\/span> <span class=\"hljs-keyword\">and<\/span> <span class=\"hljs-number\">2<\/span> <\/code><\/pre>\n<h2 id=\"strip\"><span class=\"ez-toc-section\" id=\"14_strip\"><\/span>14. strip()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Python&#8217;s\u00a0<strong>strip()<\/strong>\u00a0removes leading characters from a string. It repeatedly removes the first character from the string, if it matches any of the supplied characters.<\/p>\n<p>If you don&#8217;t specify a character, strip removes all leading whitespace characters from the string.<\/p>\n<p>The example code below removes the letter\u00a0<strong>P<\/strong>\u00a0and the space before it from the string:<\/p>\n<pre><code class=\"hljs xml\">st = <span class=\"hljs-symbol\">\"<\/span> Python tutorial<span class=\"hljs-symbol\">\"<\/span>\r\nst = st.strip(<span class=\"hljs-symbol\">\"<\/span> P<span class=\"hljs-symbol\">\"<\/span>)\r\n<span class=\"hljs-keyword\">print<\/span>(st)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; ython tutorial<\/code><\/pre>\n<p>You can replace\u00a0<strong>(&#8221; P&#8221;)<\/strong>\u00a0with\u00a0<strong>(&#8220;P&#8221;)<\/strong> to see what happens.<\/p>\n<h2 id=\"abs\"><span class=\"ez-toc-section\" id=\"15_abs\"><\/span>15. abs()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Using the <strong>abs()<\/strong> function,\u00a0 you can neutralize negative mathematical outputs\u00a0It can come in handy in computational programming or data science operations.<\/p>\n<p>See the example below for how it works:<\/p>\n<pre><code class=\"hljs xml\">neg = 4 - 9\r\npos = abs(neg)\r\n<span class=\"hljs-keyword\">print<\/span>(pos)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; 5<\/code><\/pre>\n<h2 id=\"upper\"><span class=\"ez-toc-section\" id=\"_16_upper\"><\/span>\u00a016. upper()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <strong>upper()<\/strong> method converts string characters into their uppercase equivalent.<\/p>\n<pre><code class=\"hljs xml\">y = <span class=\"hljs-symbol\">\"<\/span>Python tutorial<span class=\"hljs-symbol\">\"<\/span>\r\ny = y.upper()\r\n<span class=\"hljs-keyword\">print<\/span>(y)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; PYTHON TUTORIAL<\/code><\/pre>\n<h2 id=\"lower\"><span class=\"ez-toc-section\" id=\"17_lower\"><\/span>17. lower()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Python&#8217;s <strong>lower()\u00a0<\/strong>is the opposite of\u00a0<strong>upper().\u00a0<\/strong>So it converts string characters to lowercases:<\/p>\n<pre><code class=\"hljs xml\">y = <span class=\"hljs-symbol\">\"<\/span>PYTHON TUTORIAL<span class=\"hljs-symbol\">\"<\/span>\r\ny = y.lower()\r\n<span class=\"hljs-keyword\">print<\/span>(y)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; python tutorial<\/code><\/pre>\n<h2 id=\"sorted\"><span class=\"ez-toc-section\" id=\"18_sorted\"><\/span>18. sorted()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0<strong>sorted()<\/strong>\u00a0function works by making a list from an iterable and then arranging its values in descending or ascending order:<\/p>\n<pre><code class=\"hljs xml\">f = {<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-number\">4<\/span>, <span class=\"hljs-number\">9<\/span>, <span class=\"hljs-number\">3<\/span>} <span class=\"hljs-comment\"># Try it on a set<\/span>\r\nsort = {<span class=\"hljs-symbol\">\"<\/span>G<span class=\"hljs-symbol\">\"<\/span>:8, <span class=\"hljs-symbol\">\"<\/span>A<span class=\"hljs-symbol\">\"<\/span>:5, <span class=\"hljs-symbol\">\"<\/span>B<span class=\"hljs-symbol\">\"<\/span>:9, <span class=\"hljs-symbol\">\"<\/span>F<span class=\"hljs-symbol\">\"<\/span>:3} # Try it on a dictionary\r\n<span class=\"hljs-keyword\">print<\/span>(sorted(f, reverse=<span class=\"hljs-keyword\">True<\/span>)) <span class=\"hljs-comment\"># Descending<\/span>\r\n<span class=\"hljs-keyword\">print<\/span>(sorted(sort.values())) <span class=\"hljs-comment\"># Ascending (default)<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; \r\n<span class=\"hljs-selector-attr\">[9, 4, 3, 1]<\/span>\r\n<span class=\"hljs-selector-attr\">[3, 5, 8, 9]<\/span><\/code><\/pre>\n<h2 id=\"join\"><span class=\"ez-toc-section\" id=\"19_join\"><\/span>19. join()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The\u00a0<strong>join()<\/strong>\u00a0function lets you merge string items in a list.<\/p>\n<p>You only need to specify a delimiter and the target list to use it:<\/p>\n<pre><code class=\"hljs xml\">a = [<span class=\"hljs-symbol\">\"<\/span>Python<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>tutorial<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>on<span class=\"hljs-symbol\">\"<\/span>, <span class=\"hljs-symbol\">\"<\/span>MUO<span class=\"hljs-symbol\">\"<\/span>]\r\na = <span class=\"hljs-symbol\">\"<\/span> <span class=\"hljs-symbol\">\"<\/span>.join(a)\r\n<span class=\"hljs-keyword\">print<\/span>(a)\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">strong<\/span>&gt;<\/span>Output:<span class=\"hljs-tag\">strong<\/span>&gt; Python tutorial on MUO<\/code><\/pre>\n<h2 id=\"replace\"><span class=\"ez-toc-section\" id=\"20_replace\"><\/span>20. replace()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Python&#8217;s\u00a0<strong>replace()<\/strong>\u00a0method lets you replace some parts of a string with another character. It&#8217;s often handy in data science, especially during data cleaning.<\/p>\n<p>The\u00a0<strong>replace()<\/strong>\u00a0method accepts two parameters: the replaced character and the one you&#8217;ll like to replace it with.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"21_bin\"><\/span><strong>21. bin()<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This function converts an integer to a binary string that has the prefix 0b. Also, the integer passed could be negative or positive. Its time complexity for a number n is O(log(n))<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<pre> bin(integer)<\/pre>\n<p>where the integer is any value passed to receive its binary form.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<blockquote><p>print(bin(8))<\/p><\/blockquote>\n<p><strong>Output: \u00a0<\/strong><\/p>\n<pre>0b1000<\/pre>\n<h3>22. filter()<\/h3>\n<p>This function creates a new iterator from an existing one (such as a list, tuple, or dictionary) that filters elements. It checks whether the given condition is available in the sequence or not and then prints the output. The time complexity of the filter function is O(n).<\/p>\n<p><strong>Syntax:\u00a0<\/strong><\/p>\n<pre>filter(function, iterable)<\/pre>\n<p>where function refers to the function which will be used in a program, iterable refers to the value that will be iterated in the program.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<blockquote><p>c = [\u2018Ant\u2019,\u2019Lizard\u2019,\u2019Mosquito\u2019,\u2019Snake\u2019]\n<p>def vowels(x):<\/p>\n<p>return x[0].lower() in \u2018aeiou\u2019<\/p>\n<p>items = filter(vowels, c)<\/p>\n<p>print(list(items))<\/p><\/blockquote>\n<p><strong>Output:<\/strong><\/p>\n<pre> ['Ant']<\/pre>\n<p 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><\/p>\n<h3>23. exec()<\/h3>\n<p>This function executes the given condition and prints the output in python expression. It executes the program dynamically Python exec() function executes the dynamically created program, which is either a string or a code object. If it is a string, then it is parsed as a Python statement and then executed; else, a syntax error occurs.<\/p>\n<p><strong>Syntax:\u00a0<\/strong><\/p>\n<pre>exec(object[, globals[, locals]])<\/pre>\n<p>where the object can be a string or object code, globals can be a dictionary and the parameter is optional, and locals can be a mapping object and are also optional.<\/p>\n<p><strong>For Example:<\/strong><\/p>\n<blockquote><p>exec(print(sum(2,8)))<\/p><\/blockquote>\n<p><strong>Output:<\/strong><\/p>\n<pre>10<\/pre>\n<div class=\"text\">\n<p>With these in-built functions, you can make complex applications very easy. Use it whenever you\u2019re working on any Python application to be handy.<\/p>\n<p><a href=\"https:\/\/bit.ly\/3ELmCiA\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-25522670 size-full\" src=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png\" alt=\"Python and Machine Learning Rectangle\" width=\"970\" height=\"250\" srcset=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1.png 970w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-300x77.png 300w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-768x198.png 768w, https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/04\/Python-and-Machine-Learning-Rectangle-1-750x193.png 750w\" sizes=\"auto, (max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<\/div>\n<p>Writing less code is a great way of crafting more readable, functional programs. You shouldn&#8217;t waste valuable time recreating Python functions or methods that are readily available. You might end up doing this if you&#8217;re not familiar with Python&#8217;s built-in tools, though.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python is one of the most lucrative programming languages. According to research, there were approximately\u00a010 million Python developers\u00a0in 2020 worldwide and the count is increasing day by day. It provides ease in building a number of applications, web development processes, and a lot more. When it comes to making a program short and clear, we [&hellip;]<\/p>\n","protected":false},"author":111,"featured_media":25527023,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[802,1888],"tags":[],"class_list":["post-25526480","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>Python In-Built Functions You Should Know - 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\/python-in-built-functions-you-should-know\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python In-Built Functions You Should Know - Entri Blog\" \/>\n<meta property=\"og:description\" content=\"Python is one of the most lucrative programming languages. According to research, there were approximately\u00a010 million Python developers\u00a0in 2020 worldwide and the count is increasing day by day. It provides ease in building a number of applications, web development processes, and a lot more. When it comes to making a program short and clear, we [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/\" \/>\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-06-05T10:44:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-22T11:24:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.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=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/\"},\"author\":{\"name\":\"Feeba Mahin\",\"@id\":\"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36\"},\"headline\":\"Python In-Built Functions You Should Know\",\"datePublished\":\"2022-06-05T10:44:27+00:00\",\"dateModified\":\"2022-11-22T11:24:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/\"},\"wordCount\":1334,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/entri.app\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png\",\"articleSection\":[\"Articles\",\"Python Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/\",\"url\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/\",\"name\":\"Python In-Built Functions You Should Know - Entri Blog\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png\",\"datePublished\":\"2022-06-05T10:44:27+00:00\",\"dateModified\":\"2022-11-22T11:24:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage\",\"url\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png\",\"contentUrl\":\"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png\",\"width\":820,\"height\":615,\"caption\":\"Python In-Built Functions You Should Know\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#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\":\"Python In-Built Functions You Should Know\"}]},{\"@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":"Python In-Built Functions You Should Know - 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\/python-in-built-functions-you-should-know\/","og_locale":"en_US","og_type":"article","og_title":"Python In-Built Functions You Should Know - Entri Blog","og_description":"Python is one of the most lucrative programming languages. According to research, there were approximately\u00a010 million Python developers\u00a0in 2020 worldwide and the count is increasing day by day. It provides ease in building a number of applications, web development processes, and a lot more. When it comes to making a program short and clear, we [&hellip;]","og_url":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/","og_site_name":"Entri Blog","article_publisher":"https:\/\/www.facebook.com\/entri.me\/","article_published_time":"2022-06-05T10:44:27+00:00","article_modified_time":"2022-11-22T11:24:42+00:00","og_image":[{"width":820,"height":615,"url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.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":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#article","isPartOf":{"@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/"},"author":{"name":"Feeba Mahin","@id":"https:\/\/entri.app\/blog\/#\/schema\/person\/f036dab84abae3dcc9390a1110d95d36"},"headline":"Python In-Built Functions You Should Know","datePublished":"2022-06-05T10:44:27+00:00","dateModified":"2022-11-22T11:24:42+00:00","mainEntityOfPage":{"@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/"},"wordCount":1334,"commentCount":0,"publisher":{"@id":"https:\/\/entri.app\/blog\/#organization"},"image":{"@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png","articleSection":["Articles","Python Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/","url":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/","name":"Python In-Built Functions You Should Know - Entri Blog","isPartOf":{"@id":"https:\/\/entri.app\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage"},"image":{"@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage"},"thumbnailUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png","datePublished":"2022-06-05T10:44:27+00:00","dateModified":"2022-11-22T11:24:42+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#primaryimage","url":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png","contentUrl":"https:\/\/entri.app\/blog\/wp-content\/uploads\/2022\/06\/Python-In-Built-Functions-You-Should-Know.png","width":820,"height":615,"caption":"Python In-Built Functions You Should Know"},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/blog\/python-in-built-functions-you-should-know\/#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":"Python In-Built Functions You Should Know"}]},{"@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\/25526480","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=25526480"}],"version-history":[{"count":8,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25526480\/revisions"}],"predecessor-version":[{"id":25547732,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/posts\/25526480\/revisions\/25547732"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media\/25527023"}],"wp:attachment":[{"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/media?parent=25526480"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/categories?post=25526480"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entri.app\/blog\/wp-json\/wp\/v2\/tags?post=25526480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}