<?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: Priscillah Nalubega</title>
    <description>The latest articles on DEV Community by Priscillah Nalubega (@priscillahnalubega).</description>
    <link>https://dev.to/priscillahnalubega</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%2F499722%2F023cab79-87ff-4738-b027-08e43b092343.jpeg</url>
      <title>DEV Community: Priscillah Nalubega</title>
      <link>https://dev.to/priscillahnalubega</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/priscillahnalubega"/>
    <language>en</language>
    <item>
      <title>JavaScript FUNCTIONS</title>
      <dc:creator>Priscillah Nalubega</dc:creator>
      <pubDate>Mon, 11 Oct 2021 17:23:56 +0000</pubDate>
      <link>https://dev.to/luxdevhq/javascript-functions-257f</link>
      <guid>https://dev.to/luxdevhq/javascript-functions-257f</guid>
      <description>&lt;p&gt;
Understanding functions is so crucial when learning any programming language and it isn’t any different when it comes to JavaScript. JavaScript has a diverse use of functions and one them are their use in the place of special syntax for object-oriented programing found in other programming languages. In this article we are going to discuss the following:
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; How to define and use  a function&lt;/li&gt;
&lt;li&gt;Passing parameters to a function&lt;/li&gt;
&lt;li&gt;Pre-defined functions that are available to you &lt;/li&gt;
&lt;li&gt; The scope of variables in JavaScript&lt;/li&gt;
&lt;li&gt;The Concept that functions are just data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
Before we dive into the soup, I will assume that you have an understanding of computer basics, HTML and CSS basics as well as some basics in JavaScript.
&lt;/p&gt;

&lt;p&gt;With all that in mind let’s dive into the wonderful world of JavaScript Functions.&lt;/p&gt;

&lt;h3&gt;
What is a function?
&lt;/h3&gt;

&lt;p&gt;
A function is a block of code with a name, and since it has a name it can be reused over and over again. 
&lt;/p&gt;

&lt;h2&gt;Function Declaration&lt;/h2&gt;

&lt;p&gt;A function declaration also known as a function statement is made up of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Function Statement with the function keyword&lt;/li&gt;
&lt;li&gt;The name of the function&lt;/li&gt;
&lt;li&gt;A list of parameters(arguments) to the function enclosed in parentheses and separated by commas. &lt;/li&gt;
&lt;li&gt;The body of the function which contains the code&lt;/li&gt;
&lt;li&gt;The return statement which gives the out put of the function&lt;/li&gt;
&lt;li&gt;The JavaScript Statement that defines the function, enclosed in curly brackets.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nb"&gt;Function&lt;/span&gt; &lt;span class="nf"&gt;sum &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
      &lt;span class="nx"&gt;Let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;
The Function sum takes two parameters, a and b. The function consists of two statements; one that declares a new variable c and assigns it the sum of a and b and the other statement that returns the value of c. The statement return specifies the value returned by the function. Primitive (such as number) parameters are passed to the functions by value. If you pass an object as a parameter and the function changes the objects properties, that change is visible outside the function.  
&lt;/p&gt;

&lt;h3&gt;Function Expressions&lt;/h3&gt;

&lt;p&gt;A function can also be created using function expression. Such a function doesn’t necessarily need to have a name like the latter way of declaring functions. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
       &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt;   &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inorder to make debugging easier a name can be given to a function  for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// 9&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;Calling a Function&lt;/h2&gt;

&lt;p&gt;
Now that we have glanced into what a function is and how it is declared, let’s now see how we can execute these functions.  Calling the function actually performs the specified actions with the indicated parameters as defined when declaring the functions.
You could call it as follows ;
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This statement  calls  the function with arguments of 5,5. The Function excutes its statements and returns  the value of 10 .
&lt;/p&gt;

&lt;h3&gt;Parameters&lt;/h3&gt;

&lt;p&gt;
If you are to recall what we have discussed in the previous section,  when declaring a function you   specify the parameters the function expects to receive when it’s called in the parentheses. A may not require any parameters but when it does and you forget to pass them, JavaScript will assign the value undefined to the one that you didn’t fill in.
For example;&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// NAN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The function call will return NAN (Not A Number) because it tries to sum 4 and undefined. Therefore, make sure you pass a function with correct values and the correct number of values.&lt;/p&gt;

&lt;h3&gt; Pre-defined functions in JavaScript&lt;/h3&gt;

&lt;p&gt;Let’s have a look at some of  the in-built functions in JavaScript available for to use.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; parseInt ()&lt;/li&gt;
&lt;li&gt; parseFloat ()&lt;/li&gt;
&lt;li&gt; isNaN ()&lt;/li&gt;
&lt;li&gt; isFinite ()&lt;/li&gt;
&lt;li&gt; eval ()&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt; parseInt ()&lt;/h3&gt;

&lt;p&gt;parseInt () takes any type of data and converts it into an integer. If it fails it returns NAN. For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;parseInt &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// 1234&lt;/span&gt;
&lt;span class="nf"&gt;parseInt &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;ABC123&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// NAN&lt;/span&gt;
&lt;span class="nf"&gt;parseInt &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mi"&gt;1234&lt;/span&gt;&lt;span class="nx"&gt;AB&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// 1234&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;parseFloat ()&lt;/h3&gt;

&lt;p&gt;parseFloat () is similar to parseInt() but also looks for decimals when trying to figure out a number from your input&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;parseFloat &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 123&lt;/span&gt;
&lt;span class="nf"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mf"&gt;1.23&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1.23&lt;/span&gt;
&lt;span class="nf"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="mf"&gt;1.34&lt;/span&gt;&lt;span class="nx"&gt;abc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1.34&lt;/span&gt;
&lt;span class="nf"&gt;parseFloat &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bcd&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// NAN &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both parseInt () and parseFloat () give up at the first occurance of an unexpected character, like a letter even though the rest of the string might be numbers.&lt;/p&gt;

&lt;h3&gt;isNAN ()&lt;/h3&gt;

&lt;p&gt;isNAN () is used to check whethe the input value is a valid number that can be used safely in an arithemetic operation. This is another convenient way of verifying whether the function parseInt and parseFloat succeed.&lt;br&gt;
For example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;isNAN &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;NAN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nf"&gt;isNAN &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nf"&gt;isNAN &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.34&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// FALSE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;isFinite () &lt;/h3&gt;

&lt;p&gt;isFinite () checks if An input is a  number  that  is neither  inifinity nor NAN.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;isFinite &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;infinity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nf"&gt;isFinite &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nf"&gt;isFinite &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;egrye123&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// &lt;/span&gt;
&lt;span class="nf"&gt;isFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="nx"&gt;gttf345&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;eval ()&lt;/h3&gt;

&lt;p&gt;eval () takes a string input and executes it as JavaScript Code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;eval &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However you should avoid executing JavaScript from a string as it imposes an enormous risk.&lt;/p&gt;

&lt;h2&gt;Scope of Variables&lt;/h2&gt;   

&lt;p&gt; 
In JavaScript variables are defined in a function scope, meaning that variables defined inside a function cannot be accessed from anywhere outside the function since that variable is defined only in the scope of the function.  In contrast, a function defined in global scope can access all variables defined in the global scope.&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
         &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nb"&gt;global&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// 2&lt;/span&gt;
&lt;span class="nf"&gt;func&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// local&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, you now have a profound understanding of JavaScript Functions. This article lays a foundation that will allow you to grasp advanced JavaScript concepts like object oriented JavaScript and patterns. Till next time, thank you for reading&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functional</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SIMPLE BLOG APP</title>
      <dc:creator>Priscillah Nalubega</dc:creator>
      <pubDate>Thu, 26 Aug 2021 20:31:32 +0000</pubDate>
      <link>https://dev.to/priscillahnalubega/simple-blog-app-219e</link>
      <guid>https://dev.to/priscillahnalubega/simple-blog-app-219e</guid>
      <description>&lt;h1&gt; SIMPLE  BLOG APP &lt;/h1&gt;

&lt;p&gt; This is a simple blog app where users can:
 &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Register and login into the app&lt;/li&gt;
&lt;li&gt; See posts&lt;/li&gt;
&lt;li&gt;Create posts&lt;/li&gt;
&lt;li&gt;Update posts&lt;/li&gt;
&lt;li&gt; And delete posts&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The user can also logout of the app &lt;/p&gt;
&lt;h2&gt;Requirements&lt;/h2&gt;
&lt;p&gt;To be able to run the the program on your local machine you should have the following&lt;/p&gt;
note: its been tested on windows 10, python 3.9.6
&lt;ul&gt;
&lt;li&gt;install a virtual environment&lt;/li&gt;
&lt;li&gt;install flask&lt;/li&gt; 
&lt;li&gt;install wtforms for the login and registration forms&lt;/li&gt;
&lt;li&gt;sqlalchemy for the database &lt;/li&gt;
&lt;li&gt;install bcrypt to hash the passwords&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Setting up the environment&lt;/h2&gt;
&lt;p&gt;install a virtual environment on your windows machine:
In your Windows command shell prompt type in:
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install virtualenv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once inside the project folder run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;virtualenv &amp;lt;env&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the activate your virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.\&amp;lt;env&amp;gt;\Scripts\activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;To Run the code &lt;/h2&gt;

&lt;p&gt;still in your virtual enviroment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set FLASK_APP=run.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flask run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you will now be able to explore the app on your local machine&lt;/p&gt;

&lt;p&gt; the source code to the app &lt;a href="https://github.com/priscillahnalubega/python_blog_app"&gt;is here&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;thanks for reading.&lt;/p&gt;

</description>
      <category>python</category>
      <category>flask</category>
      <category>datascience</category>
      <category>database</category>
    </item>
    <item>
      <title>Python Boot Camp Experience!!!</title>
      <dc:creator>Priscillah Nalubega</dc:creator>
      <pubDate>Tue, 10 Aug 2021 14:13:02 +0000</pubDate>
      <link>https://dev.to/priscillahnalubega/python-boot-camp-experience-4d5h</link>
      <guid>https://dev.to/priscillahnalubega/python-boot-camp-experience-4d5h</guid>
      <description>&lt;p&gt;Friday 6th August, 2021, made the end of week the of the python boot camp at lux tech academy. For so long I have been trying to learn python on my own and most of the times it ends fatally. The constant bugs, indention errors almost made me give up learning python entirely but that's all part of the learning process. In my recent quest to master programming, a friend of mine referred me to the lux tech academy boot camp where have  learnt and familiarized my self with a lot of new stuff thus being a beginner for the nth time now.
&lt;/p&gt;

&lt;p&gt;
Though my experience cannot be limited to what am going to list down it doesn’t stop me from sharing a few lessons.
&lt;/p&gt;

&lt;h1&gt;INTRODUCTION&lt;/h1&gt;

&lt;p&gt; Week one commenced with a variety of talks from how to be abadass python developer to setting up the environment and writing clean code. I learnt the professional way of writing python code that using the &lt;a href="https://cheatography.com/jmds/cheat-sheets/python-pep8-style-guide/"&gt; &lt;b&gt;pep8&lt;/b&gt;&lt;/a&gt; standard. To make my learning easier I used &lt;a href="https://www.pythontutorial.net/"&gt;Python Tutorial website&lt;/a&gt; for reference. &lt;a href="https://scrimba.com/learn/python"&gt;Scrimba&lt;/a&gt; is also a nice place to start on your journey of being a python developer. I also learnt how to write and publish technical articles 
&lt;/p&gt; 

&lt;h2&gt;Hello world!&lt;/h2&gt;

&lt;p&gt;
As our mentor during the program always quotes "if you can write “hello world” you can change the world" we commenced with learning the basics of the python language which included the syntax, data types, key-words  and styles of writing python  code. At the end of the week I able to build a &lt;a href="https://github.com/priscillahnalubega/password-genarator"&gt;random password generator&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;Happy coding&lt;/h2&gt;

&lt;p&gt;
The happy phrase that sends off all programmers into the deep waters of writing code. During the second week of the boot camp i learnt &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lists, tuples, dictionaries and sets&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;mutable and immutable&lt;/li&gt;
&lt;li&gt;common methods in python&lt;/li&gt;
&lt;li&gt;Data structures and alogorithms&lt;/li&gt;
&lt;/ul&gt;
With that I was able to build a &lt;a href="https://github.com/priscillahnalubega/YouTube-downloader"&gt;youtube downloader&lt;/a&gt; though faced a lot of challenges with the pytube package.


&lt;h2&gt;Eat, code, sleep, &lt;/h2&gt;

&lt;p&gt;
In week 3 we where Demystifying The Flask Application factory pattern at the end of which I was able to build a &lt;a href="https://github.com/priscillahnalubega/flask-application"&gt;simple flask application.&lt;/a&gt;
&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;


&lt;p&gt; I believe that by the end of the boot camp my confidence as a software developer would have been boosted. The things I have learnt in this boot camp cant be limited to what I have shared but this all I can say for now. &lt;br&gt;
 thanks for reading, till next time chawwww!!!&lt;/p&gt;

</description>
      <category>python</category>
      <category>datascience</category>
      <category>beginners</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Introduction to Python Functions!!</title>
      <dc:creator>Priscillah Nalubega</dc:creator>
      <pubDate>Sat, 31 Jul 2021 16:07:11 +0000</pubDate>
      <link>https://dev.to/priscillahnalubega/introduction-to-python-functions-2nbb</link>
      <guid>https://dev.to/priscillahnalubega/introduction-to-python-functions-2nbb</guid>
      <description>&lt;p&gt;
Functions are named blocks of code that are designed to do one specific code. Functions facilitate reusability of code. When you want to do something repeatedly you define a function and call it whenever you need it.
&lt;/p&gt;

&lt;h2&gt;Built-In Functions&lt;/h2&gt;

&lt;p&gt; 
Python comes with several built-in functions that you can use to create wonderful programs. Here are a few but not limited to built-functions.
&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
 &lt;tr&gt;
    &lt;td&gt;print()&lt;/td&gt;
    &lt;td&gt;range()&lt;/td&gt;
    &lt;td&gt;input()&lt;/td&gt;
    &lt;td&gt;list()&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;next()&lt;/td&gt;
    &lt;td&gt;round()&lt;/td&gt;
    &lt;td&gt;max()&lt;/td&gt;
    &lt;td&gt;tuple()&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;str()&lt;/td&gt;
    &lt;td&gt;dic()&lt;/td&gt;
    &lt;td&gt;sorted()&lt;/td&gt;
    &lt;td&gt;type()&lt;/td&gt;
  &lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;object()&lt;/td&gt;
    &lt;td&gt;sum()&lt;/td&gt;
    &lt;td&gt;set()&lt;/td&gt;
    &lt;td&gt;eval()&lt;/td&gt;
  &lt;/tr&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt; Creating a function&lt;/h2&gt;

&lt;p&gt; In python a function is defined using the &lt;b&gt;def&lt;/b&gt; keyword
for example:
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello World"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt; Calling a function&lt;/h3&gt;

&lt;p&gt;The above function definition is inert until the the function is triggered or called. when you call the function:
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# Hello World
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;Arguments&lt;/h2&gt;

&lt;p&gt;
Arguments refer to the information that is passed into the function
Arguments are specified after the function name, inside the parenthesis. You can add as many arguments as you want but you have to separate them with a comma. for example:
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s"&gt;"Hello"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Hello John
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;Positional Arguments&lt;/h3&gt;

&lt;p&gt;
Because a function can have multiple parameters, a function call may need multiple arguments.You can use positional arguments which need the same order the parameters were written. This is how it works:
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;" Hello &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; from &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;John&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Uganda&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Hello John from Uganda
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine a situation when then name and the place are swapped  when the function is called.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Uganda&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;John&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Hello Uganda from John
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;
And this quite doesn't make sense.
This means that the first argument in the function call is used as the value of the first parameter and the second argument in the function call is used as the value of the second parameter.
To avoid such such situations from happening when can specify both the arguments and parameters together with the values that they take. These are called &lt;b&gt;Keyword arguments&lt;/b&gt;. Here the order of the arguments in the function call doesn't matter as long as the names of the parameters are correct.
&lt;/p&gt;

&lt;p&gt;Now we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;place&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Uganda"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Hello John from Uganda
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;Arguments and Parameters&lt;/h3&gt;

&lt;p&gt;
A parameter is the variable listed inside the parentheses in the function definition.
An argument is the value that is sent to the function when it is called.
&lt;/p&gt;

&lt;h3&gt; Number of Arguments&lt;/h3&gt;

&lt;p&gt;By default, a function should be called with correct number of arguments. Should call a function with more or less arguments than it expects it will bring an error.
&lt;/p&gt;

&lt;p&gt;for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Jack"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Ghana"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Hello Jack from Ghana
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to call this function with 1 or 3 arguments&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Jack"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Traceback (most recent call last):
  File "demo_function_args_error.py", line 4, in &amp;lt;module&amp;gt;
    greet("Jack")
TypeError: greet() missing 1 required positional argument: 'place'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;Default Value Parameter&lt;/h3&gt;

&lt;p&gt;
When writing a function, you can define a default value for each parameter. If an argument for a parameter is provided in the function call, Python uses the argument value. If not, it uses the parameter’s default value. So when you define a default value for a parameter, you can exclude the corresponding argument you’d usually write in the function call. 
&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;people&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;country&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Kenya"&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am from "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;country&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sweden"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Burundi"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Ghana"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;people&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Nigeria"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;Return Values&lt;br&gt;
To let a function return a value, use the &lt;b&gt;return&lt;/b&gt; statement:&lt;br&gt;

&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 7
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 14
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/h2&gt;



&lt;p&gt;In conclusion, we have covered:&lt;br&gt;&lt;br&gt;
&lt;/p&gt;
&lt;ul&gt;

&lt;li&gt;what are functions&lt;/li&gt;

&lt;li&gt;Built-in functions&lt;/li&gt;

&lt;li&gt;how to define functions&lt;/li&gt;

&lt;li&gt;calling functions&lt;/li&gt;

&lt;li&gt;Arguments&lt;/li&gt;

&lt;li&gt;the difference between arguments and parameters&lt;/li&gt;

&lt;li&gt;Return values&lt;/li&gt;

Hope you enjoyed reading this article. Thank you for reading. 
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>machinelearning</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Python Basics! Python 101!</title>
      <dc:creator>Priscillah Nalubega</dc:creator>
      <pubDate>Sat, 24 Jul 2021 04:47:02 +0000</pubDate>
      <link>https://dev.to/priscillahnalubega/python-basics-python-101-3ngo</link>
      <guid>https://dev.to/priscillahnalubega/python-basics-python-101-3ngo</guid>
      <description>&lt;p&gt;Python is an incredibly versatile, expansive language which due to its similarity to every day languages, is surprisingly easy to learn among inexperienced programmers. Python is very popular among professionals and students because it has a clear and simple syntax that will get you writing useful programs in short code. It even has an interactive mode, which offers immediate feedback, allowing you to test out new ideas almost instantly and has plenty of libraries allowing programmers to get a lot done with relatively little code.&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;Some of python's applications include:&lt;/h2&gt;

&lt;ul&gt;
    &lt;li&gt;Python is used in most of the search engines&lt;/li&gt;
    &lt;li&gt;Enables banks to track the money in their accounts&lt;/li&gt;
    &lt;li&gt;Used to program machines that are used to perform tricky medical procedures in hospitals.&lt;/li&gt;
    &lt;li&gt;Desktop applications&lt;/li&gt;
    &lt;li&gt;Web development&lt;/li&gt;
    &lt;li&gt;Automation&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt; Getting started with python&lt;/h3&gt;

&lt;p&gt;As you can see python is quite handy now let’s get started.
To install windows on your system visit  the python website.
&lt;a&gt;Here&lt;/a&gt; and click on the latest version of Python for Windows. The installer file will download automatically. Of the different installer options, select “executable installer”. Double-click the installer file to install Python. Choose “install for all users” and click “next” at each prompt, without changing the default settings.&lt;br&gt;
When the installation is finished, check that it was successful by opening the IDLE program. Go to the “Start” menu, choose “All Apps”, and then select “IDLE”.&lt;/p&gt;
&lt;h4&gt;On a mac&lt;/h4&gt;
&lt;p&gt;
Go to the Python website.&lt;a&gt;Here&lt;/a&gt; and click on “Downloads” to open the download page.From the downloads options, click on the latest version of Python 3 that matches your operating system. 
The Python.pkg file will download to your Mac automatically.
Install python. You’ll find the .pkg file in the “Downloads” folder. Its icon looks like an opened parcel.Double-click it to start the installation. At the prompts, click “Continue” and then “Install” to accept the default settings.
Open IDLE. When the installation is finished, check that it was successful by opening the IDLE program. Open the “Applications” folder, and then the “Python” folder. Double-click “IDLE”
&lt;/p&gt;

&lt;h3&gt;Your first program in python&lt;/h3&gt;


&lt;p&gt;This is now the time to get our hands dirty and what better way than the programmers best friend “hello world”.&lt;br&gt;&lt;br&gt;
First create a new folder where you will be saving your python files, python you wouldn’t want your files flying about the home directory. Then, launch the vs code and locate your new folder. &lt;br&gt;
In Vscode install the python extension and then create a file called hello_world.py, enter the following command and then save.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="n"&gt;World&lt;/span&gt;&lt;span class="err"&gt;’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Print () is an in-built python function that displays a message on the screen. In our example it will output ‘hello World’&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;Executing the python program&lt;/h3&gt;

&lt;p&gt;To execute our program click the run button and the output will be displayed in the terminal. The message that will be seen on the screen is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="n"&gt;World&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that you are more or less familiar with python lets dive into the basic syntax&lt;/p&gt;

&lt;h3&gt;Python basic syntax&lt;/h3&gt;

&lt;p&gt;Keywords are words that python reserves for defining the syntax and structure of the python language. Hence, you cannot use them as a regular identifier when naming variables, functions, objects, classes, and similar items or processes. They include but not limited to:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
 &lt;tr&gt;
    &lt;td&gt;and&lt;/td&gt;
    &lt;td&gt;assert&lt;/td&gt;
    &lt;td&gt;break&lt;/td&gt;
    &lt;td&gt;for&lt;/td&gt;
    &lt;td&gt;not&lt;/td&gt;
    &lt;td&gt;is&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;lambda&lt;/td&gt;
    &lt;td&gt;else&lt;/td&gt;
    &lt;td&gt;from&lt;/td&gt;
    &lt;td&gt;finally&lt;/td&gt;
    &lt;td&gt;pass&lt;/td&gt;
    &lt;td&gt;for&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;raise &lt;/td&gt;
    &lt;td&gt;None&lt;/td&gt;
    &lt;td&gt;False&lt;/td&gt;
    &lt;td&gt;del&lt;/td&gt;
    &lt;td&gt;if&lt;/td&gt;
    &lt;td&gt;import&lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;All the keywords except True, False and None are in lowercase and keywords are case sensitive.&lt;br&gt;
An identifier is a name given to a variable, class, function, string, list, dictionary, module, and other objects.&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt; Rules for writing identifiers&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; Identifiers can be a combination of letters in lowercase or uppercase or digits and an underscore. E.g  p, P lowercase, UPPERCASE, python_basics1&lt;/li&gt;
&lt;li&gt; An identifier cannot start with a digit.&lt;/li&gt;
&lt;li&gt; Key words cannot be used as identifiers.&lt;/li&gt;
&lt;li&gt; An identifier cannot contain special characters e.g  ‘#@$%&lt;/li&gt;
&lt;li&gt; An identifier can be of any length.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Naming Global Variables&lt;/h3&gt;

&lt;p&gt;Global variable names should be written in lowercase. Names consisting of two or more words should be separated by an underscore.&lt;/p&gt;

&lt;h3&gt;Naming Classes&lt;/h3&gt; 

&lt;p&gt;The CamelCase convention is used when naming a class.&lt;/p&gt;

&lt;h3&gt;Naming instance Variables&lt;/h3&gt;

&lt;p&gt;Instance variables consisting of several words should be separated by an underscore and variable names should be in lowercase   &lt;/p&gt;

&lt;h3&gt;Naming modules and Package Names&lt;/h3&gt;

&lt;p&gt;Names for modules should be in lower case, they should be short one-word&lt;/p&gt;

&lt;h3&gt;Naming functions&lt;/h3&gt;

&lt;p&gt;Function names should be in lowercase and those with several words should be separated by an underscore &lt;/p&gt;

&lt;h3&gt;Naming Constants&lt;/h3&gt;

&lt;p&gt;Constants are written in all uppercase letters and underscores are used to separate those with several words    &lt;/p&gt;

&lt;h3&gt;Comments&lt;/h3&gt;

&lt;p&gt;Comments are notes used to explain the code in the program and cannot be seen by the user running the program but can be seen in the source code. Comments make it easy for you and other programmers to evaluate your work many years after the code was written.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;#single line comment
&lt;/span&gt;&lt;span class="s"&gt;'''
multiline comment
using a doctstring
'''&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;Variables and Data Types in python&lt;/h3&gt;

&lt;h4&gt;Variables&lt;/h4&gt;

&lt;p&gt;A variable is a reserved memory location that can be used to store values. This means that when you create a variable you reserve some space in the memory. You can  declare a variable using an appropriate name and assigning a variable to it using the assignment operator (=)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;student&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"John smith"&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;20.05&lt;/span&gt;
&lt;span class="n"&gt;paid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;You don’t   need to tell python that a variable should contain a specific type of data. Python automatically identifies the data type based on the values you assign to the variable.&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt; Data types&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1). strings&lt;/strong&gt;&lt;br&gt;
  A string is an ordered series of Unicode characters which may be a combination of one or more letters, numbers, and special characters. It us an immutable data  type which ,means that when its created it cannot be changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;single_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'this is a single string'&lt;/span&gt;

&lt;span class="n"&gt;multiline_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'''
                    like
                   this
                   example
                   '''&lt;/span&gt;

&lt;span class="c1"&gt;#for escaping characters
&lt;/span&gt;&lt;span class="n"&gt;esc_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"The teacher said:\ "&lt;/span&gt;&lt;span class="n"&gt;You&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;genuis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="s"&gt;""&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;esc_string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# The teacher said: "You are a genuis"
&lt;/span&gt;
&lt;span class="c1"&gt;#concatinate stringg
&lt;/span&gt;&lt;span class="n"&gt;greet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"hello"&lt;/span&gt;
&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"john"&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;greet&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;# hello john
&lt;/span&gt;
&lt;span class="c1"&gt;#interpolation
# method 1
&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"20"&lt;/span&gt;
&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; years."&lt;/span&gt;

&lt;span class="c1"&gt;#method 2
&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"20"&lt;/span&gt;
&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'{}is {}years.formart(name,age)'&lt;/span&gt;

&lt;span class="c1"&gt;#method 3
&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John"&lt;/span&gt;
&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"20"&lt;/span&gt;
&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'{} is {}.format(first=name, last=age)'&lt;/span&gt;

&lt;span class="c1"&gt;#accessing characters in a string
&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"John Smith"&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="c1"&gt;#J
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="c1"&gt;#Smith
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2.) Number Data types&lt;/strong&gt;&lt;br&gt;
There are 3 numeric data types in python i.e int, float and complex&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;normal_integers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;46&lt;/span&gt;
&lt;span class="n"&gt;floating_point_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;50.04&lt;/span&gt;
&lt;span class="n"&gt;complex_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;

&lt;span class="c1"&gt;# converting from one numerical Type to Another
&lt;/span&gt;&lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;56&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;3.0004&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;complex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;Arithmetic Operators&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 5 (addition)
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 5 (subtraction)
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 18 (multiplication)
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;46&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 23 (division)
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 9 (exponent)
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 3 (modulus)
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# 15 (floor division)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3). Booleans&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4). Lists&lt;/strong&gt;&lt;br&gt;
A list is one of the most commonly used sequences and it is the most flexible type. It can hold one data type or a combination of several data types. A list is mutable that is you can add, remove or modify its elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# can create a an empty list with this syntax 
&lt;/span&gt;&lt;span class="n"&gt;my_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="c1"&gt;# lists with integers
&lt;/span&gt;&lt;span class="n"&gt;num_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# list with strings
&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Mary"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Peter"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# list with mixed data types
&lt;/span&gt;&lt;span class="n"&gt;mixed_list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# methods on lists
&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Mary"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Sophy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Peter"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;# append
&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Jerry"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# insert
&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"Tom"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# remove
&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;removed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Sophy"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# get length
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;children&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5). Tuples&lt;/strong&gt;&lt;br&gt;
Tuples are just the reverse of lists. They are immutable and surrounded by ().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;new_tuple&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"b"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"c"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"e"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_tuple&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;# 5
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# d
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6). Dictionaries&lt;/strong&gt;&lt;br&gt;
This is unordered collection of key-value pairs which are separated by a colon &lt;strong&gt;,&lt;/strong&gt; and enclosed in curly braces &lt;strong&gt;{}&lt;/strong&gt;. A dictionary can contain any data type and is mutable however its keys are immutable and can only contain numbers, tuples and  strings&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;ages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="s"&gt;"John"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Mary"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Tom"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="s"&gt;"Jerry"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;19&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# access, modify, delete
&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Mary&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="c1"&gt;# 20
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ages&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;  &lt;span class="c1"&gt;#  4
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This marks the end of our introduction, I hope by now you know what python is why choose python, applications of python and how to install it on your machine. We have gone through how to save python files and execute them, the basic syntax in python and the various data types. Thank you for reading&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
