<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: enosemi</title>
    <description>The latest articles on DEV Community by enosemi (@enosemi).</description>
    <link>https://dev.to/enosemi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F783071%2Ffc105e7c-5fbd-4dd9-b19b-0225781698e5.jpg</url>
      <title>DEV Community: enosemi</title>
      <link>https://dev.to/enosemi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/enosemi"/>
    <language>en</language>
    <item>
      <title>Easy understanding of functions in python</title>
      <dc:creator>enosemi</dc:creator>
      <pubDate>Thu, 30 Dec 2021 13:11:42 +0000</pubDate>
      <link>https://dev.to/enosemi/easy-understanding-of-functions-in-python-1508</link>
      <guid>https://dev.to/enosemi/easy-understanding-of-functions-in-python-1508</guid>
      <description>&lt;p&gt;We should all understand a function is a block of organized reusable code for performing single or related action. Python has many built-in functions that we have probably used e.g &lt;code&gt;print()&lt;/code&gt;,&lt;code&gt;input()&lt;/code&gt;, etc. But there are also user-defined functions which allows you to create a block of code to perform your bidding at any time it is called.&lt;/p&gt;

&lt;p&gt;Now let's look at the python function syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
def functionname(parameters):
   '''block of code'''
   pass

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is as simple as that, next is explaining the use of each keywords in the syntax.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;def&lt;/code&gt; keyword is also know as  define is the first keyword that a function should begin with.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Parameters&lt;/code&gt; or &lt;code&gt;arguments&lt;/code&gt; are placed within the parentheses and we use them inside our function body&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The code block begins after a colon and is usually indented&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's put this into practice and write a function that takes the sum of two numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def sum(num1, num2):
      '''this function adds two numbers'''
      Return num1 + num2

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code shows the function name &lt;code&gt;sum&lt;/code&gt; that has two parameters for calculating the sum of two numbers&lt;/p&gt;

&lt;h2&gt;
  
  
  How to call a function
&lt;/h2&gt;

&lt;p&gt;In the previous code we wrote our function wasn't called so if we execute the command it will return nothing. To call a function we just type the function name and the desired parameters.&lt;br&gt;
 Let's try another example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Def sum(a , b):
    #this function add two numbers
    Return num1 + num2
#now call the function
sum(2,5)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How To Define A Function(User-Defined Functions).
&lt;/h2&gt;

&lt;p&gt;The four steps to defining a function in Python are the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use the keyword def to declare the function and follow this up with the function name.&lt;/li&gt;
&lt;li&gt;Add parameters to the function: they should be within the parentheses of the function. End your line with a colon.&lt;/li&gt;
&lt;li&gt;Add statements that the functions should execute.&lt;/li&gt;
&lt;li&gt;End your function with a return statement if the function should output something. Without the return statement, your function will return an object None.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finally I want us to know we have two types of functions in python which are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Built-in functions that were developed with the language e.g min()&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;user-defined functions that are created by the users to solve their problem.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>python</category>
    </item>
  </channel>
</rss>
