<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Jason - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Jason - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 03 Jun 2026 17:23:30 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/svenss/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ C++ String – std::string Example in C++ ]]>
                </title>
                <description>
                    <![CDATA[ Strings are essential components in any programming language, and C++ is no exception. Whether you want to store text, manipulate it, or accept keyboard inputs and outputs, understanding what strings are and how to effectively use them is extremely i... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/c-string-std-string-example-in-cpp/</link>
                <guid isPermaLink="false">66d45f35b6b7f664236cbdd9</guid>
                
                    <category>
                        <![CDATA[ C++ ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jason ]]>
                </dc:creator>
                <pubDate>Mon, 31 Jan 2022 23:37:41 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/01/c---string.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Strings are essential components in any programming language, and C++ is no exception.</p>
<p>Whether you want to store text, manipulate it, or accept keyboard inputs and outputs, understanding what strings are and how to effectively use them is extremely important.</p>
<p>This article will teach everything you need to know about handling and working with strings in C++.</p>
<h2 id="heading-what-is-a-string">What is a String?</h2>
<p>Strings, at their core, are essentially collections of characters. Some examples include "Hello World", "My name is Bob", and so on. They're enclosed in double quotes <code>"</code>.</p>
<p>In C++, we have two types of strings:</p>
<ol>
<li><p>C-style strings</p>
</li>
<li><p><code>std::string</code>s (from the C++ Standard string class)</p>
</li>
</ol>
<p>You can very easily create your own string class with their own little functions, but it's not something we're going to get into in this article.</p>
<h1 id="heading-c-style-strings">C-style Strings</h1>
<p>These are strings derived from the C programming language and they continue to be supported in C++. These "collections of characters" are stored in the form of arrays of type <code>char</code> that are <em>null-terminated</em> (the <code>\0</code> null character).</p>
<h4 id="heading-how-to-define-a-c-style-string">How to define a C-style string:</h4>
<pre><code class="lang-c"><span class="hljs-keyword">char</span> str[] = <span class="hljs-string">"c string"</span>;
</code></pre>
<p>Here, <code>str</code> is a <code>char</code> array of length <code>9</code> (the extra character comes from the <code>\0</code> null character that's added by the compiler).</p>
<p>Here are some other ways of defining C-style strings in C++:</p>
<pre><code class="lang-c"><span class="hljs-keyword">char</span> str[<span class="hljs-number">9</span>] = <span class="hljs-string">"c string"</span>;
<span class="hljs-keyword">char</span> str[] = {<span class="hljs-string">'c'</span>, <span class="hljs-string">' '</span>, <span class="hljs-string">'s'</span>, <span class="hljs-string">'t'</span>, <span class="hljs-string">'r'</span>, <span class="hljs-string">'i'</span>, <span class="hljs-string">'n'</span>, <span class="hljs-string">'g'</span>, <span class="hljs-string">'\0'</span>};
<span class="hljs-keyword">char</span> str[<span class="hljs-number">9</span>] = {<span class="hljs-string">'c'</span>, <span class="hljs-string">' '</span>, <span class="hljs-string">'s'</span>, <span class="hljs-string">'t'</span>, <span class="hljs-string">'r'</span>, <span class="hljs-string">'i'</span>, <span class="hljs-string">'n'</span>, <span class="hljs-string">'g'</span>, <span class="hljs-string">'\0'</span>};
</code></pre>
<h4 id="heading-how-to-pass-c-style-strings-to-a-function">How to pass C-style strings to a function</h4>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">char</span> str[] = <span class="hljs-string">"This is a C-style string"</span>;
    display(str);
}

<span class="hljs-comment">// C-style strings can be passed to functions as follows:</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">display</span><span class="hljs-params">(<span class="hljs-keyword">char</span> str[])</span> </span>{
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str &lt;&lt; <span class="hljs-string">"\n"</span>;
}
</code></pre>
<h3 id="heading-how-to-use-c-style-string-functions-in-c">How to use C-style string functions in C++</h3>
<p>The C Standard Library came with a couple of handy functions that you can use to manipulate strings. While they're not widely recommended to use (see below), you can still use them in C++ code by including the <code>&lt;cstring&gt;</code> header:</p>
<pre><code class="lang-json">#include &lt;cstring&gt; <span class="hljs-comment">// required</span>


<span class="hljs-number">1.</span> strcpy(s1,s2) --&gt; Copies string s2 into string s1.                 
<span class="hljs-number">2.</span> strcat(s1,s2) --&gt; Concatenates string s2 onto the end of string s1
<span class="hljs-number">3.</span> strlen(s1)    --&gt; Returns the length of string s1         
<span class="hljs-number">4.</span> strcmp(s1,s2) --&gt; Returns <span class="hljs-number">0</span> if s1==s2; less than <span class="hljs-number">0</span> if s1&lt;s2; greater than <span class="hljs-number">0</span> if s1&gt;s2
<span class="hljs-number">5.</span> strchr(s1,ch) --&gt; Returns a pointer to the first occurrence of character ch in string s1
<span class="hljs-number">6.</span> strstr(s1,s2) --&gt; Returns a pointer to the first string s2 in string s1
</code></pre>
<h1 id="heading-stdstring">std::string</h1>
<p>C-style strings are relatively <em>unsafe</em> – if the string/char array is not null-terminated, it can lead to a whole host of potential bugs.</p>
<p>For example, <a target="_blank" href="https://en.wikipedia.org/wiki/Buffer_overflow">buffer overflows</a> among a <a target="_blank" href="https://stackoverflow.com/questions/312570/what-are-some-of-the-drawbacks-to-using-c-style-strings">whole host of other drawbacks</a> are some reasons why the use of C-style strings are not recommended in the C++ developer community.</p>
<p>The <code>std::string</code> class that's provided by the C++ Standard Library is a much safer alternative. Here's how you use it:</p>
<h4 id="heading-how-to-define-a-stdstring">How to define a <code>std::string</code></h4>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt; </span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string&gt; // the C++ Standard String Class</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> str = <span class="hljs-string">"C++ String"</span>;
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str &lt;&lt; <span class="hljs-string">"\n"</span>; <span class="hljs-comment">// prints `C++ String`"</span>
}
</code></pre>
<p>The most obvious difference to note between C-style strings and <code>std::string</code>s is the <em>length</em> of the string. If you ever need the length of a C-style string, you'll need to compute it each time using the <code>strlen()</code> function like so:</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;cstring&gt; // required to use `strlen`</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">char</span> str[] = <span class="hljs-string">"hello world"</span>;
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-built_in">strlen</span>(str) &lt;&lt; <span class="hljs-string">"\n"</span>;
}
</code></pre>
<p>If you don't store this in a variable and require it in multiple parts of your program, you can quickly observe how expensive this option is.</p>
<p>On the other hand, a <code>std::string</code> string already has an in-built length property. To access it, you use the <code>.length()</code> property as follows:</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string&gt; // required to use `std::string`</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> str = <span class="hljs-string">"freeCodeCamp"</span>;
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str.length() &lt;&lt; <span class="hljs-string">"\n"</span>;
}
</code></pre>
<p>Simple, neat, concise, but an important computational reduction.</p>
<p>But accessing the <em>length</em> property isn't the only benefit to using <code>std::string</code>s. Here are a few more examples:</p>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string&gt;</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
   <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> str = <span class="hljs-string">"freeCodeCamp"</span>;

   <span class="hljs-comment">// Inserting a single character into `str`</span>
   str.push_back(<span class="hljs-string">'s'</span>);
   <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str &lt;&lt; <span class="hljs-string">"\n"</span>; <span class="hljs-comment">// `str` is now `freeCodeCamps`</span>

   <span class="hljs-comment">// Deleting the last character from `str`</span>
   str.pop_back();
   <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str &lt;&lt; <span class="hljs-string">"\n"</span>; <span class="hljs-comment">// `str` is now `freeCodeCamp`</span>

   <span class="hljs-comment">// Resizing a string</span>
   str.resize(<span class="hljs-number">13</span>);
   <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str &lt;&lt; <span class="hljs-string">"\n"</span>; 

   <span class="hljs-comment">// Decreasing excess capacity of the string</span>
   str.shrink_to_fit()
   <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str &lt;&lt; <span class="hljs-string">"\n"</span>;
}
</code></pre>
<h4 id="heading-how-to-pass-an-stdstring-to-a-function">How to pass an <code>std::string</code> to a function</h4>
<pre><code class="lang-c++"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;iostream&gt;</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> str = <span class="hljs-string">"This is a C-style string"</span>;
    display(str);
}

<span class="hljs-comment">// Passing `std::string`s are as you would normally pass a regular object</span>
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">display</span><span class="hljs-params">(<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span> str)</span> </span>{
    <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cout</span> &lt;&lt; str &lt;&lt; <span class="hljs-string">"\n"</span>;
}
</code></pre>
<h2 id="heading-when-would-you-use-a-c-style-string-over-stdstring">When would you use a C-style string over <code>std::string</code>?</h2>
<p>By now, you should be convinced of the numerous advantages that <code>std::string</code>s have over C-style strings (most notably automatic memory management). But there are times when you'd want to use C-style strings instead:</p>
<ol>
<li><p>If you're from a C background, you might be comfortable working with C-style strings.</p>
</li>
<li><p>A <code>std::string</code>, despite its benefits, is enormously complex. Like the rest of the language, if you don't know what you're doing, it can get real complicated very quickly. Plus, it uses a ton of memory that may not be ideal for the purposes of your programs.</p>
</li>
<li><p>If you're careful to manage your program's memory during runtime (by freeing an object's memory when you're done using it), there is a performance benefit to using C-style strings considering how small and lightweight they are.</p>
</li>
</ol>
<h1 id="heading-wrapping-up">Wrapping Up</h1>
<p>I hope this article served as an introduction to strings in C++. There's <em>so much more</em> to learn about this wonderful abstraction, and I hope to write more articles delving into the more advanced concepts of strings and C++.</p>
<p>Happy learning!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Improve the Accuracy of Your Image Recognition Models ]]>
                </title>
                <description>
                    <![CDATA[ These 7 tricks and tips will take you from 50% to 90% accuracy for your image recognition models in literally minutes. So, you have gathered a dataset, built a neural network, and trained your model. But despite the hours (and sometimes days) of work... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/improve-image-recognition-model-accuracy-with-these-hacks/</link>
                <guid isPermaLink="false">66d45f379208fb118cc6cfc9</guid>
                
                    <category>
                        <![CDATA[ data analysis ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Deep Learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ image recognition ]]>
                    </category>
                
                    <category>
                        <![CDATA[ neural networks ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jason ]]>
                </dc:creator>
                <pubDate>Mon, 29 Nov 2021 17:09:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/image-recognition-model-image.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>These 7 tricks and tips will take you from 50% to 90% accuracy for your image recognition models in literally minutes.</p>
<p>So, you have gathered a dataset, built a neural network, and trained your model.</p>
<p>But despite the hours (and sometimes days) of work you've invested to create the model, it spits out predictions with an accuracy of 50–70%. Chances are, this is not what you expected.</p>
<p>Here are a few strategies, or hacks, to boost your model’s performance metrics.</p>
<h2 id="heading-1-get-more-data">1. Get More Data</h2>
<p>Deep learning models are only as powerful as the data you bring in. One of the easiest ways to increase validation accuracy is to add more data. This is especially useful if you don’t have many training instances.</p>
<p>If you’re working on image recognition models, you may consider increasing the diversity of your available dataset by employing data augmentation. These techniques include anything from flipping an image over an axis and adding noise to zooming in on the image. If you are a strong machine learning engineer, you could also try data augmentation with GANs.</p>
<p>Read more about <a target="_blank" href="https://bair.berkeley.edu/blog/2019/06/07/data_aug/">data augmentation here</a>.</p>
<p>Keras has an amazing image preprocessing class to perform data augmentation: <a target="_blank" href="https://keras.io/api/preprocessing/image/#imagedatagenerator-class">ImageDataGenerator</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-119.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Be careful that the augmentation technique you use changes the entire class of an image. For example, the image of a 3 flipped over the y-axis doesn’t make sense! [Source](https://bair.berkeley.edu/blog/2019/06/07/data_aug/" rel="noopener)</em></p>
<h2 id="heading-2-add-more-layers">2. Add More Layers</h2>
<p>Adding more layers to your model increases its ability to learn your dataset’s features more deeply. This means that it will be able to recognize subtle differences that you, as a human, might not have picked up on.</p>
<p>This hack entirely relies on the nature of the task you are trying to solve.</p>
<p>For complex tasks, such as differentiating between the breeds of cats and dogs, adding more layers makes sense because your model will be able to learn the subtle features that differentiate a poodle from a Shih Tzu.</p>
<p>For simple tasks, such as classifying cats and dogs, a simple model with few layers will do.</p>
<p>More layers -&gt; More nuanced model.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-120.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Photo by [Unsplash](https://unsplash.com/@alvannee?utm_source=medium&amp;utm_medium=referral" rel="photo-creator noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener"&gt;Alvan Nee on &lt;a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral" rel="photo-source noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener noopener)</em></p>
<h2 id="heading-3-change-your-image-size">3. Change Your Image Size</h2>
<p>When you preprocess your images for training and evaluation, there is a lot of experimentation you can do with regards to the image size.</p>
<p>If you choose an image size that is too small, your model will not be able to pick up on the distinctive features that help with image recognition.</p>
<p>Conversely, if your images are too big, it increases the computational resources required by your computer and/or your model might not be sophisticated enough to process them.</p>
<p>Common image sizes include 64x64, 128x128, 28x28 (MNIST), and 224x224 (VGG-16).</p>
<p>Keep in mind that most preprocessing algorithms do not consider the aspect ratio of the image, so smaller-sized images might appear to have shrunk over a certain axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-121.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Converting an image from a large resolution to a small size, like 28x28, usually ends up with a lot of pixelation that tends to have negative effects on your model’s performance. [Source](https://dribbble.com/shots/4829233-Pixelated-Mona-Lisa" rel="noopener)</em></p>
<h2 id="heading-4-increase-epochs">4. Increase Epochs</h2>
<p><em>Epochs</em> are basically how many times you pass the entire dataset through the neural network. Incrementally train your model with more epochs with intervals of +25, +100, and so on.</p>
<p>Increasing epochs makes sense only if you have a lot of data in your dataset. However, your model will eventually reach a point where increasing epochs will not improve accuracy.</p>
<p>At this point, you should consider playing around with your model’s learning rate. This little hyperparameter dictates whether your model reaches its global minimum (the ultimate goal for neural nets) or gets stuck in a local minimum.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-122.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Global Minimum is the ultimate goal for neural networks. [Source](https://www.dna-ghost.com/single-post/2018/03/13/Neural-network-Escaping-from-variety-of-non-global-minimum-traps" rel="noopener)</em></p>
<h2 id="heading-5-decrease-colour-channels">5. Decrease Colour Channels</h2>
<p>Colour channels reflect the dimensionality of your image arrays. Most colour (RGB) images are composed of three colour channels, while grayscale images have just one channel.</p>
<p>The more complex the colour channels are, the more complex the dataset is and the longer it will take to train the model.</p>
<p>If colour is not such a significant factor in your model, you can go ahead and convert your colour images to grayscale.</p>
<p>You can even consider other colour spaces, like HSV and L<em>a</em>b.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-123.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>RGB images are composed of three colour channels: red, green, and blue. [Source](https://www.youtube.com/watch?v=ZqUotba3V5Y" rel="noopener)</em></p>
<h2 id="heading-6-transfer-learning">6. Transfer Learning</h2>
<p>Transfer learning involves the use of a pre-trained model, such as YOLO and ResNet, as a starting point for most computer vision and natural language processing tasks.</p>
<p>Pre-trained models are state-of-the-art deep learning models that were trained on millions and millions of samples, and often for months. These models have an astonishingly huge capability of detecting nuances in different images.</p>
<p>These models can be used as a base for your model. Most models are so good that you won’t need to add convolutional and pooling Layers.</p>
<p>Read more about <a target="_blank" href="https://machinelearningmastery.com/transfer-learning-for-deep-learning/">using transfer learning</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-124.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Transfer learning can greatly improve your model’s accuracy from ~50% to 90%! Source: [Nvidia blog](https://www.nvidia.com/content/dam/en-zz/en_sg/ai-innovation-day-2019/assets/pdf/9_NVIDIA-Transfer-Learning-Toolkit-for-Intelligent-Video-Analytics.pdf" rel="noopener)</em></p>
<h2 id="heading-final-thoughts">Final Thoughts</h2>
<p>The hacks above offer a base for you to optimize a model. To really fine tune a model, you’ll need to consider tuning the various hyperparameters and functions involved in your model, such as the learning rate (as discussed above), activation functions, loss functions, and so on.</p>
<p>This hack comes as an “I hope you know what you’re doing” warning because there is a wider scope to mess up your model.</p>
<h3 id="heading-always-save-your-models">Always Save Your Models</h3>
<p>Always save your model every time you make a change to your deep learning model. This will help you reuse a previous configuration of the model if it provides greater accuracy.</p>
<p>Most deep learning frameworks like Tensorflow and Pytorch have a “save model” method.</p>
<pre><code class="lang-python"><span class="hljs-comment"># In Tensorflow</span>
model.save(<span class="hljs-string">'model.h5'</span>) <span class="hljs-comment"># Saves the entire model to a single artifact</span>

<span class="hljs-comment"># In Pytorch</span>
torch.save(model, PATH)
</code></pre>
<p>There are countless other ways to further optimize your deep learning, but the hacks described above serve as a base in the optimization part of deep learning.</p>
<p><a target="_blank" href="http://twitter.com/jasmcaus"><em>Tweet at me</em></a> letting me know what your favourite hack is!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ All the Math You Need to Know in Artificial Intelligence ]]>
                </title>
                <description>
                    <![CDATA[ I’m an AI researcher, and I’ve received quite a few emails asking me just how much math is required in Artificial Intelligence. I won’t lie: it’s a lot of math. And this is one of the reasons AI puts off many beginners. After much research and talks ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/all-the-math-you-need-in-artificial-intelligence/</link>
                <guid isPermaLink="false">66d45f31246e57ac83a2c76d</guid>
                
                    <category>
                        <![CDATA[ Advanced Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Artificial Intelligence ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jason ]]>
                </dc:creator>
                <pubDate>Wed, 24 Nov 2021 00:12:40 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/math-in-ai-article-image.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>I’m an AI researcher, and I’ve received quite a few emails asking me just how much math is required in Artificial Intelligence.</p>
<p>I won’t lie: <strong>it’s a lot of math</strong>.</p>
<p>And this is one of the reasons AI puts off many beginners. After much research and talks with several veterans in the field, I’ve compiled this no-nonsense guide that covers all of the fundamentals of the math you’ll need to know.</p>
<p>The concepts mentioned below are usually covered over several semesters in college, but I’ve boiled them down to the core principles that you can focus on.</p>
<p>This guide is an absolute life-saver for beginners, so you can study the topics that matter most. But it's an even better resource for practitioners, such as myself, who require a quick breeze-through on these concepts.</p>
<blockquote>
<p>Note: You don’t need to know all of the concepts (below) in order to get your first job in AI. All you need is a <em>firm grasp</em> of the fundamentals. Focus on those and consolidate them.</p>
</blockquote>
<h2 id="heading-1-algebra-you-need-to-know-for-ai">1. Algebra You Need to Know for AI</h2>
<p><img src="https://images.unsplash.com/photo-1509228627152-72ae9ae6848d?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDd8fG1hdGh8ZW58MHx8fHwxNjM3MzM3MTM1&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Pencil on system of equations: Photo by [Unsplash](https://unsplash.com/@antoine1003?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit&quot;>Antoine Dautry / <a href=&quot;https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit)" width="2000" height="1333" loading="lazy"></p>
<p>Knowledge of algebra is perhaps fundamental to math in general. Besides mathematical operations like addition, subtraction, multiplication and division, you’ll need to know the following:</p>
<ul>
<li><p><a target="_blank" href="http://www.mclph.umn.edu/mathrefresh/exponents.html"><strong>Exponents</strong></a></p>
</li>
<li><p><a target="_blank" href="https://tutorial.math.lamar.edu/classes/alg/Radicals.aspx"><strong>Radicals</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=pGg40oiQsUk&amp;feature=youtu.be"><strong>Factorials</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.youtube.com/watch?v=LDfaYXXAcHY&amp;feature=youtu.be"><strong>Summations</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.khanacademy.org/math/pre-algebra/pre-algebra-exponents-radicals"><strong>Scientific Notations</strong></a></p>
</li>
</ul>
<h2 id="heading-2-linear-algebra-you-need-to-know-for-ai">2. Linear Algebra You Need to Know for AI</h2>
<p>Linear Algebra is the primary mathematical computation tool in Artificial Intelligence and in many other areas of Science and Engineering. With this field, you need to understand 4 primary mathematical objects and their properties:</p>
<ul>
<li><p><a target="_blank" href="http://www.sciencebits.com/vector_algebra"><strong>Scalars</strong></a> **** — a single number (can be real or natural).</p>
</li>
<li><p><a target="_blank" href="http://www.sciencebits.com/vector_algebra"><strong>Vectors</strong></a> — a list of numbers, arranged in order. Consider them as points in space with each element representing the coordinate along an axis.</p>
</li>
<li><p><a target="_blank" href="https://www.mathsisfun.com/algebra/matrix-introduction.html"><strong>Matrices</strong></a> — a 2-D array of numbers where each number is identified by 2 indices.</p>
</li>
<li><p><a target="_blank" href="https://mathworld.wolfram.com/Tensor.html"><strong>Tensors</strong></a> **** — an N-D array (N&gt;2) of numbers, arranged on a regular grid with N-axes. Important in Machine Learning, Deep Learning and <a target="_blank" href="https://github.com/jasmcaus/caer">Computer Vision</a>.</p>
</li>
<li><p><a target="_blank" href="https://www.mathsisfun.com/algebra/eigenvalue.html"><strong>Eigenvectors &amp; Eigenvalues</strong></a> — special vectors and their corresponding scalar quantity. Understand the significance and how to find them.</p>
</li>
<li><p><a target="_blank" href="https://web.mit.edu/be.400/www/SVD/Singular_Value_Decomposition.htm"><strong>Singular Value Decomposition</strong></a> **** — factorization of a matrix into 3 matrices. Understand the properties and applications.</p>
</li>
<li><p><a target="_blank" href="https://royalsocietypublishing.org/doi/10.1098/rsta.2015.0202"><strong>Principal Component Analysis (PCA)</strong></a> — understand the significance, properties, and applications.</p>
</li>
</ul>
<p>Properties such as the <a target="_blank" href="https://betterexplained.com/articles/vector-calculus-understanding-the-dot-product/">Dot product</a>, <a target="_blank" href="http://hyperphysics.phy-astr.gsu.edu/hbase/vvec.html">Vector product</a> and the <a target="_blank" href="https://handwiki.org/wiki/Hadamard_product_%28matrices%29">Hadamard product</a> are useful to know as well.</p>
<h2 id="heading-3-calculus-you-need-to-know-for-ai">3. Calculus You Need to Know for AI</h2>
<p><img src="https://images.unsplash.com/photo-1596495577886-d920f1fb7238?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fG1hdGh8ZW58MHx8fHwxNjM3MzM3MTM1&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Photo by [Unsplash](https://unsplash.com/@jeswinthomas?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit&quot;>Jeswin Thomas / <a href=&quot;https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit)" width="2000" height="1327" loading="lazy"></p>
<p>Calculus deals with changes in parameters, functions, errors and approximations. Working knowledge of multi-dimensional calculus is imperative in Artificial Intelligence.</p>
<p>The following are the most important concepts (albeit non-exhaustive) in Calculus:</p>
<ul>
<li><p><a target="_blank" href="https://www.mathsisfun.com/calculus/derivatives-introduction.html"><strong>Derivatives</strong></a> — rules (addition, product, chain rule, and so on), hyperbolic derivatives (tanh, cosh, and so on) and partial derivatives.</p>
</li>
<li><p><a target="_blank" href="http://www.personal.rdg.ac.uk/~sis01xh/teaching/CY4C9/ANN3.pdf"><strong>Vector/Matrix Calculus</strong></a> — different derivative operators (Gradient, Jacobian, Hessian and Laplacian)</p>
</li>
<li><p><a target="_blank" href="https://towardsdatascience.com/gradient-descent-algorithm-and-its-variants-10f652806a3"><strong>Gradient Algorithms</strong></a> **** — local/global maxima and minima, saddle points, convex functions, batches and mini-batches, stochastic gradient descent, and performance comparison.</p>
</li>
</ul>
<h2 id="heading-4-statistics-amp-probability-concepts-you-need-to-know-for-ai">4. Statistics &amp; Probability Concepts You Need to Know for AI</h2>
<p><img src="https://images.unsplash.com/photo-1609017909889-d7b582c072f7?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDF8fHByb2JhYmlsaXR5fGVufDB8fHx8MTYzNzMzNzUxOQ&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Photo by [Unsplash](https://unsplash.com/@tamiminaser?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit&quot;>Naser Tamimi / <a href=&quot;https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit)" width="2000" height="1335" loading="lazy"></p>
<p>This topic will probably take up a significant chunk of your time. Good news: these concepts aren’t difficult, so there’s no reason why you shouldn’t master them.</p>
<ul>
<li><p><a target="_blank" href="https://www.dummies.com/education/math/statistics/statistics-for-dummies-cheat-sheet/"><strong>Basic Statistics</strong></a> — Mean, median, mode, variance, covariance, and so on.</p>
</li>
<li><p><a target="_blank" href="http://www.milefoot.com/math/stat/prob-rules.htm"><strong>Basic rules in probability</strong></a> **** — events (dependent and independent), sample spaces, conditional probability.</p>
</li>
<li><p><a target="_blank" href="https://www.khanacademy.org/math/statistics-probability/random-variables-stats-library"><strong>Random variables</strong></a> **** — continuous and discrete, expectation, variance, distributions (joint and conditional).</p>
</li>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/bayes-rule-explained/"><strong>Bayes’ Theorem</strong></a> — calculates validity of beliefs. Bayesian software helps machines recognize patterns and make decisions.</p>
</li>
<li><p><a target="_blank" href="https://towardsdatascience.com/probability-concepts-explained-maximum-likelihood-estimation-c7b4342fdbb1"><strong>Maximum Likelihood Estimation (MLE)</strong></a> **** — parameter estimation. Requires knowledge of fundamental probability concepts (joint probability and independence of events).</p>
</li>
<li><p><a target="_blank" href="https://www.stat.tamu.edu/~twehrly/611/distab.pdf"><strong>Common Distributions</strong></a> — binomial, poisson, bernoulli, gaussian, exponential.</p>
</li>
</ul>
<h2 id="heading-5-information-theory-concepts-you-need-to-know-for-ai">5. Information Theory Concepts You Need to Know for AI</h2>
<p><img src="https://images.unsplash.com/photo-1560416313-414b33c856a9?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fGluZm9ybWF0aW9ufGVufDB8fHx8MTYzNzMzNzU3Mw&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Photo by [Unsplash](https://unsplash.com/@giuliamay?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit&quot;>Giulia May / <a href=&quot;https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit)" width="2000" height="1500" loading="lazy"></p>
<p>This is an important field that has made significant contributions to AI and Deep Learning, and is yet unknown to many. Think of it as an amalgamation of calculus, statistics, and probability.</p>
<ul>
<li><p><a target="_blank" href="https://mathoverflow.net/questions/146463/what-is-entropy-really"><strong>Entropy</strong></a> **** — also called Shannon Entropy. Used to measure the uncertainty in an experiment.</p>
</li>
<li><p><a target="_blank" href="https://machinelearningmastery.com/cross-entropy-for-machine-learning"><strong>Cross-Entropy</strong></a> **** — compares two probability distributions and tells us how similar they are.</p>
</li>
<li><p><a target="_blank" href="https://www.countbayesie.com/blog/2017/5/9/kullback-leibler-divergence-explained"><strong>Kullback Leibler Divergence</strong></a> **** — another measure of how similar two probability distributions are.</p>
</li>
<li><p><a target="_blank" href="https://www.cis.upenn.edu/~cis262/notes/Example-Viterbi-DNA.pdf"><strong>Viterbi Algorithm</strong></a> **** — widely used in Natural Language Processing (NLP) and Speech.</p>
</li>
<li><p><a target="_blank" href="https://hackernoon.com/information-theory-of-neural-networks-c96a0f0a8d9"><strong>Encoder-Decoder</strong></a> <strong>—</strong> used in Machine Translation RNNs and other models.</p>
</li>
</ul>
<h2 id="heading-math-is-fun">Math is Fun!</h2>
<p>If you are terrified at the mere mention of “math”, you’re probably not going to have much fun in Artificial Intelligence.</p>
<p>But if you’re willing to invest time to improve your familiarity with the principles underlying calculus, linear algebra, stats, and probability, nothing — not even math — should get in the way of you getting into AI.</p>
<p>PS: Math <em>really</em> is fun. As you go deeper into math, be sure to understand the beauty of a certain math concept and <em>how</em> it affects something. You’ll soon share the unbridled passion that many mathematicians and AI Scientists have!</p>
<blockquote>
<p>A tip: Treat mathematical concepts as a pay-as-you-go: whenever a foreign concept pops up, grab it and devour it! The guide above presents a minimal, yet comprehensive, resource to understand any kind of topic or concept in AI.</p>
</blockquote>
<p>Happy learning!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ SQL Commands Cheat Sheet – How to Learn SQL in 10 Minutes ]]>
                </title>
                <description>
                    <![CDATA[ I’m an AI researcher, so one of the main things I deal with is data. A lot of it. With more than 2.5 exabytes of data generated every day, it comes as no surprise that this data needs to be stored somewhere where we can access it when we need ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-sql-in-10-minutes/</link>
                <guid isPermaLink="false">66d45f39052ad259f07e4aea</guid>
                
                    <category>
                        <![CDATA[ cheatsheet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ database ]]>
                    </category>
                
                    <category>
                        <![CDATA[ MySQL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SQL ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jason ]]>
                </dc:creator>
                <pubDate>Tue, 23 Nov 2021 15:36:59 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/sql-in-10-min-image.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>I’m an AI researcher, so one of the main things I deal with is data. A <em>lot</em> of it.</p>
<p>With more than <a target="_blank" href="https://www.socialmediatoday.com/news/how-much-data-is-generated-every-minute-infographic-1/525692/">2.5 exabytes of data generated <em>every day</em></a>, it comes as no surprise that this data needs to be stored somewhere where we can access it when we need it.</p>
<p>This article will walk you through a hackable cheatsheet to get you up and running with SQL quickly.</p>
<h2 id="heading-what-is-sql">What is SQL?</h2>
<p>SQL stands for Structured Query Language. It is a language for relational database management systems. SQL is used today to store, retrieve, and manipulate data within relational databases.</p>
<p>Here’s what a basic relational database looks like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745433576314/ef41d0e6-7187-4856-927f-c1b899e3b73b.png" alt="Source: https://assets-global.website-files.com/5debb9b4f88fbc3f702d579e/5e3c1a71724a38245aa43b02_99bf70d46cc247be878de9d3a88f0c44.png" class="image--center mx-auto" width="773" height="367" loading="lazy"></p>
<p>Using SQL, we can interact with the database by writing <em>queries.</em></p>
<p>Here’s what an example query looks like:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> customers;
</code></pre>
<p>Using this <code>SELECT</code> statement, the query selects <em>all</em> the data from all the columns in the customer’s table and returns data like so:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-55.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Source: Database Guide</em></p>
<p>The asterisk wildcard character (*) refers to “<em>all</em>” and selects <em>all</em> the rows and columns. We can replace it with specific column names instead — here only those columns will be returned by the query</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> FirstName, LastName <span class="hljs-keyword">FROM</span> customers;
</code></pre>
<p>Adding a <code>WHERE</code> clause allows you to filter what gets returned:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> customers <span class="hljs-keyword">WHERE</span> age &gt;= <span class="hljs-number">30</span> <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> age <span class="hljs-keyword">ASC</span>;
</code></pre>
<p>This query returns all data from the products table with an <em>age</em> value of greater than 30.</p>
<p>The use of <code>ORDER BY</code> keyword just means the results will be ordered using the age column from the lowest value to the highest</p>
<p>Using the <code>INSERT INTO</code> statement, we can add new data to a table. Here’s a basic example adding a new user to the customers table:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> customers(FirstName, LastName, address, email)
<span class="hljs-keyword">VALUES</span> (<span class="hljs-string">'Alice'</span>, <span class="hljs-string">'Bob'</span>, <span class="hljs-string">'McLaren Vale, South Australia'</span>, <span class="hljs-string">'test@fakeGmail.com'</span>);
</code></pre>
<p>Of course, these examples demonstrate only a very small selection of what the SQL language can do. We'll learn more about it in this guide.</p>
<h2 id="heading-why-learn-sql">Why Learn SQL?</h2>
<p>We live in the age of Big Data, where data is used extensively to find insights and inform strategy, marketing, advertising and a plethora of other operations.</p>
<p>Big businesses like Google, Amazon, AirBnb utilize large, relational databases as a basis of improving customer experience. Understanding SQL is a great skill to have not only for data scientists and analysts but for everyone.</p>
<p><em>How do you think that you suddenly got a Youtube ad on shoes when just a few minutes ago, you were Googling your favourite shoes? That’s SQL (or a form of SQL) at work!</em></p>
<h2 id="heading-sql-vs-mysql">SQL vs MySQL</h2>
<p>Before we move on, I just want to clarify an often-confused topic — the difference between SQL and MySQL. As it turns out, they <em>aren’t</em> the same thing!</p>
<p>SQL is a language, while MySQL is a system to implement SQL.</p>
<p><strong>SQL</strong> outlines syntax that allows you to write queries that manage relational databases.</p>
<p><strong>MySQL</strong> is a database <em>system</em> that runs on a server. It allows you to write queries using SQL syntax to manage MySQL databases.</p>
<p>In addition to MySQL, there are other systems that implement SQL. Some of the more popular ones include:</p>
<ul>
<li><p>SQLite</p>
</li>
<li><p>Oracle Database</p>
</li>
<li><p>PostgreSQL</p>
</li>
<li><p>Microsoft SQL Server</p>
</li>
</ul>
<h2 id="heading-how-to-install-mysql">How to Install MySQL</h2>
<p>For most cases, MySQL is the preferred choice for a database management system. Many popular Content Management Systems (like Wordpress) use MySQL by default, so using MySQL to manage those applications can be a good idea.</p>
<p>In order to use MySQL, you’ll need to install it on your system:</p>
<h3 id="heading-install-mysql-on-windows">Install MySQL on Windows</h3>
<p>The recommended way to install MySQL on Windows is by using the MSI installer from the <a target="_blank" href="https://dev.mysql.com/doc/mysql-installer/en/mysql-installer.html">MySQL website</a>.</p>
<p><a target="_blank" href="https://www.liquidweb.com/kb/install-mysql-windows/">This resource will guide you with the installation process.</a></p>
<h3 id="heading-install-mysql-on-macos">Install MySQL on macOS</h3>
<p>On macOS, installing MySQL also involves downloading an <a target="_blank" href="https://dev.mysql.com/doc/mysql-osx-excerpt/8.0/en/osx-installation-pkg.html">installer.</a></p>
<p><a target="_blank" href="https://dev.mysql.com/doc/mysql-osx-excerpt/5.7/en/osx-installation-pkg.html">This resource will guide you through the installation process.</a></p>
<h2 id="heading-how-to-use-mysql">How to Use MySQL</h2>
<p>With MySQL now installed on your system, I recommend that you use some sort of <em>SQL management application</em> to make managing your databases a much easier process.</p>
<p>There are lots of apps to choose from which largely do the same job, so it’s down to your own personal preference on which one to use:</p>
<ul>
<li><p><a target="_blank" href="https://www.mysql.com/products/workbench/">MySQL Workbench</a> developed by Oracle</p>
</li>
<li><p><a target="_blank" href="http://phpmyadmin.net/">phpMyAdmin</a> (operates in the web browser)</p>
</li>
<li><p><a target="_blank" href="https://www.heidisql.com/">HeidiSQL</a> <strong>(Recommended for Windows)</strong></p>
</li>
<li><p><a target="_blank" href="https://www.sequelpro.com/">Sequel Pro</a> <strong>(Recommended for macOS)</strong></p>
</li>
</ul>
<p>When you’re ready to start writing your own SQL queries, consider importing dummy data rather than creating your own database.</p>
<p>Here are some <a target="_blank" href="https://dev.mysql.com/doc/index-other.html">dummy databases</a> that are available for download free of charge.</p>
<h2 id="heading-sql-cheatsheet-the-icing-on-the-cake">SQL Cheatsheet – The Icing on the Cake</h2>
<h3 id="heading-sql-keywords">SQL Keywords</h3>
<p>Here you can find a collection of keywords used in SQL statements, a description, and where appropriate an example. Some of the more advanced keywords have their own dedicated section.</p>
<p>Where MySQL is mentioned next to an example, this means this example is only applicable to MySQL databases (as opposed to any other database system).</p>
<pre><code class="lang-sql">ADD <span class="hljs-comment">-- Adds a new column to an existing table</span>

ADD CONSTRAINT <span class="hljs-comment">-- Creates a new constraint on an existing table, which is used to specify rules for any data in the table.</span>

<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-comment">-- Adds, deletes or edits columns in a table. It can also be used to add and delete constraints in a table, as per the above.</span>

<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-comment">-- Changes the data type of a table’s column.</span>

<span class="hljs-keyword">ALL</span> <span class="hljs-comment">-- Returns true if all of the subquery values meet the passed condition.</span>

<span class="hljs-keyword">AND</span> <span class="hljs-comment">-- Used to join separate conditions within a WHERE clause.</span>

<span class="hljs-keyword">ANY</span> <span class="hljs-comment">-- Returns true if any of the subquery values meet the given condition.</span>

<span class="hljs-keyword">AS</span> <span class="hljs-comment">-- Renames a table or column with an alias value which only exists for the duration of the query.</span>

<span class="hljs-keyword">ASC</span> <span class="hljs-comment">-- Used with ORDER BY to return the data in ascending order.</span>

<span class="hljs-keyword">BETWEEN</span> <span class="hljs-comment">-- Selects values within the given range.</span>

<span class="hljs-keyword">CASE</span> <span class="hljs-comment">-- Changes query output depending on conditions.</span>

<span class="hljs-keyword">CHECK</span> <span class="hljs-comment">-- Adds a constraint that limits the value which can be added to a column.</span>

<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">DATABASE</span> <span class="hljs-comment">-- Creates a new database.</span>

<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-comment">-- Creates a new table. </span>

<span class="hljs-keyword">DEFAULT</span> <span class="hljs-comment">-- Sets a default value for a column</span>

<span class="hljs-keyword">DELETE</span> <span class="hljs-comment">-- Delete data from a table.</span>

<span class="hljs-keyword">DESC</span> <span class="hljs-comment">-- Used with ORDER BY to return the data in descending order.</span>

<span class="hljs-keyword">DROP</span> <span class="hljs-keyword">COLUMN</span> <span class="hljs-comment">-- Deletes a column from a table.</span>

<span class="hljs-keyword">DROP</span> <span class="hljs-keyword">DATABASE</span> <span class="hljs-comment">-- Deletes the entire database.</span>

<span class="hljs-keyword">DROP</span> DEAFULT <span class="hljs-comment">-- Removes a default value for a column.</span>

<span class="hljs-keyword">DROP</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-comment">-- Deletes a table from a database.</span>

<span class="hljs-keyword">EXISTS</span> <span class="hljs-comment">-- Checks for the existence of any record within the subquery, returning true if one or more records are returned.</span>

<span class="hljs-keyword">FROM</span> <span class="hljs-comment">-- Specifies which table to select or delete data from.</span>

<span class="hljs-keyword">IN</span> <span class="hljs-comment">--  Used alongside a WHERE clause as a shorthand for multiple OR conditions.</span>

<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-comment">-- Adds new rows to a table.</span>

<span class="hljs-keyword">IS</span> <span class="hljs-literal">NULL</span> <span class="hljs-comment">-- Tests for empty (NULL) values.</span>

<span class="hljs-keyword">IS</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-comment">-- The reverse of NULL. Tests for values that aren’t empty / NULL.</span>

<span class="hljs-keyword">LIKE</span> <span class="hljs-comment">-- Returns true if the operand value matches a pattern.</span>

<span class="hljs-keyword">NOT</span> <span class="hljs-comment">-- Returns true if a record DOESN’T meet the condition.</span>

<span class="hljs-keyword">OR</span> <span class="hljs-comment">-- Used alongside WHERE to include data when either condition is true.</span>

<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> <span class="hljs-comment">-- Used to sort the result data in ascending (default) or descending order through the use of ASC or DESC keywords.</span>

<span class="hljs-keyword">ROWNUM</span> <span class="hljs-comment">-- Returns results where the row number meets the passed condition.</span>

<span class="hljs-keyword">SELECT</span> <span class="hljs-comment">-- Used to select data from a database, which is then returned in a results set.</span>

<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">DISTINCT</span> <span class="hljs-comment">-- Sames as SELECT, except duplicate values are excluded.</span>

<span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-comment">-- Copies data from one table and inserts it into another.</span>

<span class="hljs-keyword">SELECT</span> TOP <span class="hljs-comment">-- Allows you to return a set number of records to return from a table.</span>

<span class="hljs-keyword">SET</span> <span class="hljs-comment">-- Used alongside UPDATE to update existing data in a table.</span>

<span class="hljs-keyword">SOME</span> <span class="hljs-comment">-- Identical to ANY.</span>

TOP <span class="hljs-comment">-- Used alongside SELECT to return a set number of records from a table.</span>

<span class="hljs-keyword">TRUNCATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-comment">-- Similar to DROP, but instead of deleting the table and its data, this deletes only the data.</span>

<span class="hljs-keyword">UNION</span> <span class="hljs-comment">-- Combines the results from 2 or more SELECT statements and returns only distinct values.</span>

<span class="hljs-keyword">UNION</span> <span class="hljs-keyword">ALL</span> <span class="hljs-comment">-- The same as UNION, but includes duplicate values.</span>

<span class="hljs-keyword">UNIQUE</span> <span class="hljs-comment">-- This constraint ensures all values in a column are unique.</span>

<span class="hljs-keyword">UPDATE</span> <span class="hljs-comment">-- Updates existing data in a table.</span>

<span class="hljs-keyword">VALUES</span> <span class="hljs-comment">-- Used alongside the INSERT INTO keyword to add new values to a table.</span>

<span class="hljs-keyword">WHERE</span> <span class="hljs-comment">-- Filters results to only include data which meets the given condition.</span>
</code></pre>
<h3 id="heading-comments-in-sql">Comments in SQL</h3>
<p>Comments allow you to explain sections of your SQL statements, without being executed directly.</p>
<p>In SQL, there are 2 types of comments, single line and multiline.</p>
<h4 id="heading-single-line-comments-in-sql">Single Line Comments in SQL</h4>
<p>Single line comments start with ‘- -’. Any text after these 2 characters to the end of the line will be ignored.</p>
<pre><code class="lang-sql"><span class="hljs-comment">-- This part is ignored</span>

<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> customers;
</code></pre>
<h4 id="heading-multiline-comments-in-sql">Multiline Comments in SQL</h4>
<p>Multiline comments start with /* and end with */. They stretch across multiple lines until the closing characters have been found.</p>
<pre><code class="lang-json"><span class="hljs-comment">/*

This is a multiline comment.
It can span across multiple lines.

*/</span>

SELECT * FROM customers;

<span class="hljs-comment">/*

This is another comment. 
You can even put code within a comment to prevent its execution

SELECT * FROM icecreams;

*/</span>
</code></pre>
<h3 id="heading-data-types-in-mysql">Data Types in MySQL</h3>
<p>When creating a new table or editing an existing one, you must specify the type of data that each column accepts.</p>
<p><a target="_blank" href="https://www.datadriveninvestor.com/2020/05/04/could-machine-learning-and-nlp-have-predicted-oils-crash-the-answer-is-yes/">In this example</a>, data passed to the <code>id</code> column must be an int (integer), while the <code>FirstName</code> column has a <code>VARCHAR</code> data type with a maximum of 255 characters.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> customers(
<span class="hljs-keyword">id</span> <span class="hljs-built_in">int</span>,
FirstName <span class="hljs-built_in">varchar</span>(<span class="hljs-number">255</span>)
);
</code></pre>
<h4 id="heading-1-string-data-types">1. String Data Types</h4>
<pre><code class="lang-sql">CHAR(size) <span class="hljs-comment">-- Fixed length string which can contain letters, numbers and special characters. The size parameter sets the maximum string length, from 0 – 255 with a default of 1.</span>

VARCHAR(size) <span class="hljs-comment">-- Variable length string similar to CHAR(), but with a maximum string length range from 0 to 65535.</span>

BINARY(size) <span class="hljs-comment">-- Similar to CHAR() but stores binary byte strings.</span>

VARBINARY(size) <span class="hljs-comment">-- Similar to VARCHAR() but for binary byte strings.</span>

TINYBLOB <span class="hljs-comment">-- Holds Binary Large Objects (BLOBs) with a max length of 255 bytes.</span>

TINYTEXT <span class="hljs-comment">-- Holds a string with a maximum length of 255 characters. Use VARCHAR() instead, as it’s fetched much faster.</span>

TEXT(size) <span class="hljs-comment">-- Holds a string with a maximum length of 65535 bytes. Again, better to use VARCHAR().</span>

BLOB(size) <span class="hljs-comment">-- Holds Binary Large Objects (BLOBs) with a max length of 65535 bytes.</span>

MEDIUMTEXT <span class="hljs-comment">-- Holds a string with a maximum length of 16,777,215 characters.</span>

MEDIUMBLOB <span class="hljs-comment">-- Holds Binary Large Objects (BLOBs) with a max length of 16,777,215 bytes.</span>

LONGTEXT <span class="hljs-comment">-- Holds a string with a maximum length of 4,294,967,295 characters.</span>

LONGBLOB <span class="hljs-comment">-- Holds Binary Large Objects (BLOBs) with a max length of 4,294,967,295 bytes.</span>

ENUM(a, b, c, etc…) <span class="hljs-comment">-- A string object that only has one value, which is chosen from a list of values which you define, up to a maximum of 65535 values. If a value is added which isn’t on this list, it’s replaced with a blank value instead.</span>

<span class="hljs-keyword">SET</span>(a, b, c, etc…) <span class="hljs-comment">-- A string object that can have 0 or more values, which is chosen from a list of values which you define, up to a maximum of 64 values.</span>
</code></pre>
<h4 id="heading-2-numeric-data-types">2. Numeric Data Types</h4>
<pre><code class="lang-sql">BIT(size) <span class="hljs-comment">-- A bit-value type with a default of 1. The allowed number of bits in a value is set via the size parameter, which can hold values from 1 to 64.</span>

TINYINT(size) <span class="hljs-comment">-- A very small integer with a signed range of -128 to 127, and an unsigned range of 0 to 255. Here, the size parameter specifies the maximum allowed display width, which is 255.</span>

BOOL <span class="hljs-comment">-- Essentially a quick way of setting the column to TINYINT with a size of 1. 0 is considered false, whilst 1 is considered true.</span>

BOOLEAN    <span class="hljs-comment">-- Same as BOOL.</span>

SMALLINT(size) <span class="hljs-comment">-- A small integer with a signed range of -32768 to 32767, and an unsigned range from 0 to 65535. Here, the size parameter specifies the maximum allowed display width, which is 255.</span>

MEDIUMINT(size) <span class="hljs-comment">-- A medium integer with a signed range of -8388608 to 8388607, and an unsigned range from 0 to 16777215. Here, the size parameter specifies the maximum allowed display width, which is 255.</span>

INT(size) <span class="hljs-comment">-- A medium integer with a signed range of -2147483648 to 2147483647, and an unsigned range from 0 to 4294967295. Here, the size parameter specifies the maximum allowed display width, which is 255.</span>

INTEGER(size) <span class="hljs-comment">-- Same as INT.</span>

BIGINT(size) <span class="hljs-comment">-- A medium integer with a signed range of -9223372036854775808 to 9223372036854775807, and an unsigned range from 0 to 18446744073709551615. Here, the size parameter specifies the maximum allowed display width, which is 255.</span>

FLOAT(p) <span class="hljs-comment">-- A floating point number value. If the precision (p) parameter is between 0 to 24, then the data type is set to FLOAT(), whilst if it's from 25 to 53, the data type is set to DOUBLE(). This behaviour is to make the storage of values more efficient.</span>

DOUBLE(size, d) <span class="hljs-comment">-- A floating point number value where the total digits are set by the size parameter, and the number of digits after the decimal point is set by the d parameter.</span>

DECIMAL(size, d) <span class="hljs-comment">-- An exact fixed point number where the total number of digits is set by the size parameters, and the total number of digits after the decimal point is set by the d parameter.</span>

DEC(size, d) <span class="hljs-comment">-- Same as DECIMAL.</span>
</code></pre>
<h4 id="heading-3-datetime-data-types">3. Date/Time Data Types</h4>
<pre><code class="lang-sql">DATE <span class="hljs-comment">-- A simple date in YYYY-MM–DD format, with a supported range from ‘1000-01-01’ to ‘9999-12-31’.</span>

DATETIME(fsp) <span class="hljs-comment">-- A date time in YYYY-MM-DD hh:mm:ss format, with a supported range from ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’. By adding DEFAULT and ON UPDATE to the column definition, it automatically sets to the current date/time.</span>

TIMESTAMP(fsp) <span class="hljs-comment">-- A Unix Timestamp, which is a value relative to the number of seconds since the Unix epoch (‘1970-01-01 00:00:00’ UTC). This has a supported range from ‘1970-01-01 00:00:01’ UTC to ‘2038-01-09 03:14:07’ UTC.</span>
By adding DEFAULT CURRENT_TIMESTAMP and ON <span class="hljs-keyword">UPDATE</span> <span class="hljs-keyword">CURRENT</span> <span class="hljs-built_in">TIMESTAMP</span> <span class="hljs-keyword">to</span> the <span class="hljs-keyword">column</span> definition, it automatically <span class="hljs-keyword">sets</span> <span class="hljs-keyword">to</span> <span class="hljs-keyword">current</span> <span class="hljs-built_in">date</span>/time.

<span class="hljs-built_in">TIME</span>(fsp) <span class="hljs-comment">-- A time in hh:mm:ss format, with a supported range from ‘-838:59:59’ to ‘838:59:59’.</span>

<span class="hljs-keyword">YEAR</span> <span class="hljs-comment">-- A year, with a supported range of ‘1901’ to ‘2155’.</span>
</code></pre>
<h3 id="heading-sql-operators">SQL Operators</h3>
<h4 id="heading-1-arithmetic-operators-in-sql">1. Arithmetic Operators in SQL</h4>
<pre><code class="lang-sql">+ <span class="hljs-comment">-- Add</span>
– <span class="hljs-comment">-- Subtract</span>
* <span class="hljs-comment">-- Multiply</span>
/ <span class="hljs-comment">-- Divide</span>
% <span class="hljs-comment">-- Modulus</span>
</code></pre>
<h4 id="heading-2-bitwise-operators-in-sql">2. Bitwise Operators in SQL</h4>
<pre><code class="lang-sql">&amp; <span class="hljs-comment">-- Bitwise AND</span>
| <span class="hljs-comment">-- Bitwise OR</span>
^<span class="hljs-comment">-- Bitwise XOR</span>
</code></pre>
<h4 id="heading-3-comparison-operators-in-sql">3. Comparison Operators in SQL</h4>
<pre><code class="lang-sql">= <span class="hljs-comment">-- Equal to</span>
&gt; <span class="hljs-comment">-- Greater than</span>
&lt; <span class="hljs-comment">-- Less than</span>
&gt;= <span class="hljs-comment">-- Greater than or equal to</span>
&lt;= <span class="hljs-comment">-- Less than or equal to</span>
&lt;&gt; <span class="hljs-comment">-- Not equal to</span>
</code></pre>
<h4 id="heading-4-compound-operators-in-sql">4. Compound Operators in SQL</h4>
<pre><code class="lang-sql">+= <span class="hljs-comment">-- Add equals</span>
-= <span class="hljs-comment">-- Subtract equals</span>
*= <span class="hljs-comment">-- Multiply equals</span>
/= <span class="hljs-comment">-- Divide equals</span>
%= <span class="hljs-comment">-- Modulo equals</span>
&amp;= <span class="hljs-comment">-- Bitwise AND equals</span>
^-= <span class="hljs-comment">-- Bitwise exclusive equals</span>
|*= <span class="hljs-comment">-- Bitwise OR equals</span>
</code></pre>
<h3 id="heading-sql-functions">SQL Functions</h3>
<h4 id="heading-1-string-functions-in-sql">1. String Functions in SQL</h4>
<pre><code class="lang-sql">ASCII <span class="hljs-comment">-- Returns the equivalent ASCII value for a specific character.</span>

CHAR_LENGTH <span class="hljs-comment">-- Returns the character length of a string.</span>

CHARACTER_LENGTH <span class="hljs-comment">-- Same as CHAR_LENGTH.</span>

CONCAT <span class="hljs-comment">-- Adds expressions together, with a minimum of 2.</span>

CONCAT_WS <span class="hljs-comment">-- Adds expressions together, but with a separator between each value.</span>

FIELD <span class="hljs-comment">-- Returns an index value relative to the position of a value within a list of values.</span>

FIND IN <span class="hljs-keyword">SET</span> <span class="hljs-comment">-- Returns the position of a string in a list of strings.</span>

<span class="hljs-keyword">FORMAT</span> <span class="hljs-comment">-- When passed a number, returns that number formatted to include commas (eg 3,400,000).</span>

<span class="hljs-keyword">INSERT</span> <span class="hljs-comment">-- Allows you to insert one string into another at a certain point, for a certain number of characters.</span>

<span class="hljs-keyword">INSTR</span> <span class="hljs-comment">-- Returns the position of the first time one string appears within another.</span>

<span class="hljs-keyword">LCASE</span> <span class="hljs-comment">-- Converts a string to lowercase.</span>

<span class="hljs-keyword">LEFT</span> <span class="hljs-comment">-- Starting from the left, extracts the given number of characters from a string and returns them as another.</span>

<span class="hljs-keyword">LENGTH</span> <span class="hljs-comment">-- Returns the length of a string, but in bytes.</span>

<span class="hljs-keyword">LOCATE</span> <span class="hljs-comment">-- Returns the first occurrence of one string within another,</span>

<span class="hljs-keyword">LOWER</span> <span class="hljs-comment">-- Same as LCASE.</span>

<span class="hljs-keyword">LPAD</span> <span class="hljs-comment">-- Left pads one string with another, to a specific length.</span>

<span class="hljs-keyword">LTRIM</span> <span class="hljs-comment">-- Removes any leading spaces from the given string.</span>

<span class="hljs-keyword">MID</span> <span class="hljs-comment">-- Extracts one string from another, starting from any position.</span>

<span class="hljs-keyword">POSITION</span> <span class="hljs-comment">-- Returns the position of the first time one substring appears within another.</span>

<span class="hljs-keyword">REPEAT</span> <span class="hljs-comment">-- Allows you to repeat a string</span>

<span class="hljs-keyword">REPLACE</span> <span class="hljs-comment">-- Allows you to replace any instances of a substring within a string, with a new substring.</span>

<span class="hljs-keyword">REVERSE</span>    <span class="hljs-comment">-- Reverses the string.</span>

<span class="hljs-keyword">RIGHT</span> <span class="hljs-comment">-- Starting from the right, extracts the given number of characters from a string and returns them as another.</span>

RPAD <span class="hljs-comment">-- Right pads one string with another, to a specific length.</span>

<span class="hljs-keyword">RTRIM</span> <span class="hljs-comment">-- Removes any trailing spaces from the given string.</span>

<span class="hljs-keyword">SPACE</span> <span class="hljs-comment">-- Returns a string full of spaces equal to the amount you pass it.</span>

<span class="hljs-keyword">STRCMP</span> <span class="hljs-comment">-- Compares 2 strings for differences</span>

<span class="hljs-keyword">SUBSTR</span> <span class="hljs-comment">-- Extracts one substring from another, starting from any position.</span>

<span class="hljs-keyword">SUBSTRING</span> <span class="hljs-comment">-- Same as SUBSTR</span>

SUBSTRING_INDEX    <span class="hljs-comment">-- Returns a substring from a string before the passed substring is found the number of times equals to the passed number.</span>

<span class="hljs-keyword">TRIM</span> <span class="hljs-comment">--    Removes trailing and leading spaces from the given string. Same as if you were to run LTRIM and RTRIM together.</span>

<span class="hljs-keyword">UCASE</span> <span class="hljs-comment">-- Converts a string to uppercase.</span>

<span class="hljs-keyword">UPPER</span> <span class="hljs-comment">-- Same as UCASE.</span>
</code></pre>
<h4 id="heading-2-numeric-functions-in-sql">2. Numeric Functions in SQL</h4>
<pre><code class="lang-sql">ABS <span class="hljs-comment">-- Returns the absolute value of the given number.</span>

ACOS <span class="hljs-comment">-- Returns the arc cosine of the given number.</span>

ASIN <span class="hljs-comment">-- Returns the arc sine of the given number.</span>

ATAN <span class="hljs-comment">-- Returns the arc tangent of one or 2 given numbers.</span>

ATAN2 <span class="hljs-comment">-- Returns the arc tangent of 2 given numbers.</span>

AVG <span class="hljs-comment">-- Returns the average value of the given expression.</span>

CEIL <span class="hljs-comment">-- Returns the closest whole number (integer) upwards from a given decimal point number.</span>

CEILING <span class="hljs-comment">-- Same as CEIL.</span>

COS <span class="hljs-comment">-- Returns the cosine of a given number.</span>

COT <span class="hljs-comment">-- Returns the cotangent of a given number.</span>

COUNT <span class="hljs-comment">-- Returns the amount of records that are returned by a SELECT query.</span>

DEGREES <span class="hljs-comment">-- Converts a radians value to degrees.</span>

DIV <span class="hljs-comment">-- Allows you to divide integers.</span>

EXP <span class="hljs-comment">-- Returns e to the power of the given number.</span>

FLOOR <span class="hljs-comment">-- Returns the closest whole number (integer) downwards from a given decimal point number.</span>

GREATEST <span class="hljs-comment">-- Returns the highest value in a list of arguments.</span>

LEAST <span class="hljs-comment">-- Returns the smallest value in a list of arguments.</span>

LN <span class="hljs-comment">-- Returns the natural logarithm of the given number.</span>

LOG <span class="hljs-comment">-- Returns the natural logarithm of the given number, or the logarithm of the given number to the given base.</span>

LOG10 <span class="hljs-comment">-- Does the same as LOG, but to base 10.</span>

LOG2 <span class="hljs-comment">-- Does the same as LOG, but to base 2.</span>

MAX <span class="hljs-comment">-- Returns the highest value from a set of values.</span>

MIN <span class="hljs-comment">-- Returns the lowest value from a set of values.</span>

MOD <span class="hljs-comment">-- Returns the remainder of the given number divided by the other given number.</span>

PI <span class="hljs-comment">-- Returns PI.</span>

POW <span class="hljs-comment">-- Returns the value of the given number raised to the power of the other given number.</span>

POWER <span class="hljs-comment">-- Same as POW.</span>

RADIANS <span class="hljs-comment">-- Converts a degrees value to radians.</span>

RAND <span class="hljs-comment">-- Returns a random number.</span>

ROUND <span class="hljs-comment">-- Rounds the given number to the given amount of decimal places.</span>

SIGN <span class="hljs-comment">-- Returns the sign of the given number.</span>

SIN <span class="hljs-comment">-- Returns the sine of the given number.</span>

SQRT <span class="hljs-comment">-- Returns the square root of the given number.</span>

SUM <span class="hljs-comment">-- Returns the value of the given set of values combined.</span>

TAN <span class="hljs-comment">-- Returns the tangent of the given number.</span>

<span class="hljs-keyword">TRUNCATE</span> <span class="hljs-comment">-- Returns a number truncated to the given number of decimal places.</span>
</code></pre>
<h4 id="heading-3-date-functions-in-sql">3. Date Functions in SQL</h4>
<pre><code class="lang-sql">ADDDATE <span class="hljs-comment">-- Adds a date interval (eg: 10 DAY) to a date (eg: 20/01/20) and returns the result (eg: 20/01/30).</span>

ADDTIME <span class="hljs-comment">-- Adds a time interval (eg: 02:00) to a time or datetime (05:00) and returns the result (07:00).</span>

CURDATE <span class="hljs-comment">-- Gets the current date.</span>

CURRENT_DATE <span class="hljs-comment">-- Same as CURDATE.</span>

CURRENT_TIME <span class="hljs-comment">-- Gest the current time.</span>

CURRENT_TIMESTAMP <span class="hljs-comment">-- Gets the current date and time.</span>

CURTIME <span class="hljs-comment">-- Same as CURRENT_TIME.</span>

DATE <span class="hljs-comment">-- Extracts the date from a datetime expression.</span>

DATEDIFF <span class="hljs-comment">-- Returns the number of days between the 2 given dates.</span>

DATE_ADD <span class="hljs-comment">-- Same as ADDDATE.</span>

DATE_FORMAT <span class="hljs-comment">-- Formats the date to the given pattern.</span>

DATE_SUB <span class="hljs-comment">-- Subtracts a date interval (eg: 10 DAY) to a date (eg: 20/01/20) and returns the result (eg: 20/01/10).</span>

DAY <span class="hljs-comment">-- Returns the day for the given date.</span>

DAYNAME <span class="hljs-comment">-- Returns the weekday name for the given date.</span>

DAYOFWEEK <span class="hljs-comment">-- Returns the index for the weekday for the given date.</span>

DAYOFYEAR <span class="hljs-comment">-- Returns the day of the year for the given date.</span>

EXTRACT <span class="hljs-comment">-- Extracts from the date the given part (eg MONTH for 20/01/20 = 01).</span>

FROM DAYS <span class="hljs-comment">-- Returns the date from the given numeric date value.</span>

HOUR <span class="hljs-comment">-- Returns the hour from the given date.</span>

LAST DAY <span class="hljs-comment">-- Gets the last day of the month for the given date.</span>

LOCALTIME <span class="hljs-comment">-- Gets the current local date and time.</span>

LOCALTIMESTAMP <span class="hljs-comment">-- Same as LOCALTIME.</span>

MAKEDATE <span class="hljs-comment">-- Creates a date and returns it, based on the given year and number of days values.</span>

MAKETIME <span class="hljs-comment">-- Creates a time and returns it, based on the given hour, minute and second values.</span>

MICROSECOND <span class="hljs-comment">-- Returns the microsecond of a given time or datetime.</span>

MINUTE <span class="hljs-comment">-- Returns the minute of the given time or datetime.</span>

MONTH <span class="hljs-comment">-- Returns the month of the given date.</span>

MONTHNAME <span class="hljs-comment">-- Returns the name of the month of the given date.</span>

NOW <span class="hljs-comment">-- Same as LOCALTIME.</span>

PERIOD_ADD <span class="hljs-comment">-- Adds the given number of months to the given period.</span>

PERIOD_DIFF <span class="hljs-comment">-- Returns the difference between 2 given periods.</span>

QUARTER <span class="hljs-comment">-- Returns the year quarter for the given date.</span>

SECOND <span class="hljs-comment">-- Returns the second of a given time or datetime.</span>

SEC_TO_TIME <span class="hljs-comment">-- Returns a time based on the given seconds.</span>

STR_TO_DATE <span class="hljs-comment">-- Creates a date and returns it based on the given string and format.</span>

SUBDATE <span class="hljs-comment">-- Same as DATE_SUB.</span>

SUBTIME <span class="hljs-comment">-- Subtracts a time interval (eg: 02:00) to a time or datetime (05:00) and returns the result (03:00).</span>

SYSDATE <span class="hljs-comment">-- Same as LOCALTIME.</span>

TIME <span class="hljs-comment">-- Returns the time from a given time or datetime.</span>

TIME_FORMAT <span class="hljs-comment">-- Returns the given time in the given format.</span>

TIME_TO_SEC <span class="hljs-comment">-- Converts and returns a time into seconds.</span>

TIMEDIFF <span class="hljs-comment">-- Returns the difference between 2 given time/datetime expressions.</span>

TIMESTAMP <span class="hljs-comment">-- Returns the datetime value of the given date or datetime.</span>

TO_DAYS <span class="hljs-comment">-- Returns the total number of days that have passed from ‘00-00-0000’ to the given date.</span>

WEEK <span class="hljs-comment">-- Returns the week number for the given date.</span>

WEEKDAY <span class="hljs-comment">-- Returns the weekday number for the given date.</span>

WEEKOFYEAR <span class="hljs-comment">-- Returns the week number for the given date.</span>

YEAR <span class="hljs-comment">-- Returns the year from the given date.</span>

YEARWEEK <span class="hljs-comment">-- Returns the year and week number for the given date.</span>
</code></pre>
<h4 id="heading-4-miscellaneous-functions-in-sql">4. Miscellaneous Functions in SQL</h4>
<pre><code class="lang-sql">BIN <span class="hljs-comment">-- Returns the given number in binary.</span>

BINARY <span class="hljs-comment">-- Returns the given value as a binary string.</span>

CAST <span class="hljs-comment">-- Converst one type into another.</span>

COALESCE <span class="hljs-comment">-- From a list of values, returns the first non-null value.</span>

CONNECTION_ID <span class="hljs-comment">-- For the current connection, returns the unique connection ID.</span>

CONV <span class="hljs-comment">-- Converts the given number from one numeric base system into another.</span>

CONVERT <span class="hljs-comment">-- Converts the given value into the given datatype or character set.</span>

CURRENT_USER <span class="hljs-comment">-- Returns the user and hostname which was used to authenticate with the server.</span>

DATABASE <span class="hljs-comment">-- Gets the name of the current database.</span>

GROUP BY <span class="hljs-comment">-- Used alongside aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the results.</span>

HAVING <span class="hljs-comment">-- Used in the place of WHERE with aggregate functions.</span>

IF <span class="hljs-comment">-- If the condition is true it returns a value, otherwise it returns another value.</span>

IFNULL <span class="hljs-comment">-- If the given expression equates to null, it returns the given value.</span>

ISNULL <span class="hljs-comment">-- If the expression is null, it returns 1, otherwise returns 0.</span>

LAST_INSERT_ID <span class="hljs-comment">-- For the last row which was added or updated in a table, returns the auto increment ID.</span>

NULLIF <span class="hljs-comment">-- Compares the 2 given expressions. If they are equal, NULL is returned, otherwise the first expression is returned.</span>

SESSION_USER <span class="hljs-comment">-- Returns the current user and hostnames.</span>

SYSTEM_USER <span class="hljs-comment">-- Same as SESSION_USER.</span>

USER <span class="hljs-comment">-- Same as SESSION_USER.</span>

VERSION <span class="hljs-comment">-- Returns the current version of the MySQL powering the database.</span>
</code></pre>
<h3 id="heading-wildcard-characters-in-sql">Wildcard Characters in SQL</h3>
<p>In SQL, Wildcards are special characters used with the <code>LIKE</code> and <code>NOT LIKE</code> keywords. This allows us to search for data with sophisticated patterns rather efficiently.</p>
<pre><code class="lang-sql">% <span class="hljs-comment">-- Equates to zero or more characters.</span>
<span class="hljs-comment">-- Example: Find all customers with surnames ending in ‘ory’.</span>
<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> customers
<span class="hljs-keyword">WHERE</span> surname <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'%ory'</span>;

_ <span class="hljs-comment">-- Equates to any single character.</span>
<span class="hljs-comment">-- Example: Find all customers living in cities beginning with any 3 characters, followed by ‘vale’.</span>
<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> customers
<span class="hljs-keyword">WHERE</span> city <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'_ _ _vale'</span>;

[charlist] <span class="hljs-comment">-- Equates to any single character in the list.</span>
<span class="hljs-comment">-- Example: Find all customers with first names beginning with J, K or T.</span>
<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> customers
<span class="hljs-keyword">WHERE</span> first_name <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'[jkt]%'</span>;
</code></pre>
<h3 id="heading-sql-keys">SQL Keys</h3>
<p>In relational databases, there is a concept of <em>primary</em> and <em>foreign</em> keys. In SQL tables, these are included as constraints, where a table can have a primary key, a foreign key, or both.</p>
<h4 id="heading-1-primary-keys-in-sql">1. Primary Keys in SQL</h4>
<p>A primary lets each record in a table be uniquely identified. You can only have one primary key per table, and you can assign this constraint to any single or combination of columns. However, this means each value within this column(s) needs to be unique.</p>
<p>Typically in a table, the ID column is a primary key, and is usually paired with the <code>AUTO_INCREMENT</code> keyword. This means the value increases automatically as and when new records are created.</p>
<h4 id="heading-example-mysql">Example (MySQL)</h4>
<p>Create a new table and set the primary key to the ID column.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> customers (
<span class="hljs-keyword">id</span> <span class="hljs-built_in">int</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT,
FirstName <span class="hljs-built_in">varchar</span>(<span class="hljs-number">255</span>),
<span class="hljs-keyword">Last</span> <span class="hljs-keyword">Name</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>,
address <span class="hljs-built_in">varchar</span>(<span class="hljs-number">255</span>),
email <span class="hljs-built_in">varchar</span>(<span class="hljs-number">255</span>),
PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-keyword">id</span>)
);
</code></pre>
<h4 id="heading-2-foreign-keys-in-sql">2. Foreign Keys in SQL</h4>
<p>You can apply a foreign key to one column or many. You use it to <em>link</em> 2 tables together in a relational database.</p>
<p>The table containing the foreign key is called the <em>child</em> key,</p>
<p>The table containing the referenced (or candidate) key is called the <em>parent</em> table.</p>
<p>This essentially means that the column data is shared between 2 tables, because a foreign key also prevents invalid data from being inserted which isn’t also present in the parent table.</p>
<h4 id="heading-example-mysql-1">Example (MySQL)</h4>
<p>Create a new table and turn any column that references IDs in other tables into foreign keys.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> orders (
<span class="hljs-keyword">id</span> <span class="hljs-built_in">int</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>,
user_id <span class="hljs-built_in">int</span>,
product_id <span class="hljs-built_in">int</span>,
PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-keyword">id</span>),
<span class="hljs-keyword">FOREIGN</span> <span class="hljs-keyword">KEY</span> (user_id) <span class="hljs-keyword">REFERENCES</span> <span class="hljs-keyword">users</span>(<span class="hljs-keyword">id</span>),
<span class="hljs-keyword">FOREIGN</span> <span class="hljs-keyword">KEY</span> (product_id) <span class="hljs-keyword">REFERENCES</span> products(<span class="hljs-keyword">id</span>)
);
</code></pre>
<h3 id="heading-indexes-in-sql">Indexes in SQL</h3>
<p>Indexes are attributes that can be assigned to columns that are frequently searched against to make data retrieval a quicker and more efficient process.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">INDEX</span> <span class="hljs-comment">-- Creates an index named ‘idx_test’ on the first_name and surname columns of the users table. In this instance, duplicate values are allowed.</span>
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">INDEX</span> idx_test
<span class="hljs-keyword">ON</span> <span class="hljs-keyword">users</span> (first_name, surname);
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">UNIQUE</span> <span class="hljs-keyword">INDEX</span> <span class="hljs-comment">-- The same as the above, but no duplicate values.</span>
<span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">UNIQUE</span> <span class="hljs-keyword">INDEX</span> idx_test
<span class="hljs-keyword">ON</span> <span class="hljs-keyword">users</span> (first_name, surname);
<span class="hljs-keyword">DROP</span> <span class="hljs-keyword">INDEX</span> <span class="hljs-comment">-- Removes an index.</span>
<span class="hljs-keyword">ALTER</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">users</span>
<span class="hljs-keyword">DROP</span> <span class="hljs-keyword">INDEX</span> idx_test;
</code></pre>
<h3 id="heading-sql-joins">SQL Joins</h3>
<p>In SQL, a <code>JOIN</code> clause is used to return a result which combines data from multiple tables, based on a common column which is featured in both of them.</p>
<p>There are a number of different joins available for you to use:</p>
<ul>
<li><p><strong>Inner Join (Default):</strong> Returns any records which have matching values in both tables.</p>
</li>
<li><p><strong>Left Join:</strong> Returns all of the records from the first table, along with any matching records from the second table.</p>
</li>
<li><p><strong>Right Join:</strong> Returns all of the records from the second table, along with any matching records from the first.</p>
</li>
<li><p><strong>Full Join:</strong> Returns all records from both tables when there is a match.</p>
</li>
</ul>
<p>A common way of visualising how joins work is like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-56.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://websitesetup.org/sql-cheat-sheet/"><em>Source</em></a><em>: Website Setup</em></p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> orders.id, users.FirstName, users.Surname, products.name <span class="hljs-keyword">as</span> ‘product <span class="hljs-keyword">name</span>’
<span class="hljs-keyword">FROM</span> orders
<span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> <span class="hljs-keyword">users</span> <span class="hljs-keyword">on</span> orders.user_id = users.id
<span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> products <span class="hljs-keyword">on</span> orders.product_id = products.id;
</code></pre>
<h3 id="heading-views-in-sql">Views in SQL</h3>
<p>A view is essentially an SQL results set that gets stored in the database under a label, so you can return to it later without having to rerun the query.</p>
<p>These are especially useful when you have a costly SQL query which you might need a number of times. So instead of running it over and over to generate the same results set, you can just do it once and save it as a view.</p>
<h4 id="heading-how-to-create-views-in-sql">How to Create Views in SQL</h4>
<p>To create a view, you can do so like this:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">VIEW</span> priority_users <span class="hljs-keyword">AS</span>
<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-keyword">users</span>
<span class="hljs-keyword">WHERE</span> country = ‘United Kingdom’;
</code></pre>
<p>Then in future, if you need to access the stored result set, you can do so like this:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> [priority_users];
</code></pre>
<h4 id="heading-how-to-replace-views-in-sql">How to Replace Views in SQL</h4>
<p>With the <code>CREATE OR REPLACE</code> command, you can update a view like this:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">OR</span> <span class="hljs-keyword">REPLACE</span> <span class="hljs-keyword">VIEW</span> [priority_users] <span class="hljs-keyword">AS</span>
<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-keyword">users</span>
<span class="hljs-keyword">WHERE</span> country = ‘United Kingdom’ <span class="hljs-keyword">OR</span> country=’USA’;
</code></pre>
<h4 id="heading-how-to-delete-views-in-sql">How to Delete Views in SQL</h4>
<p>To delete a view, simply use the <code>DROP VIEW</code> command.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">DROP</span> <span class="hljs-keyword">VIEW</span> priority_users;
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The majority of websites and applications use relational databases in some way or the other. This makes SQL extremely valuable to know as it allows you to create more complex, functional systems.</p>
<p>Happy learning!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Why You Should Start Using Docker Right Now ]]>
                </title>
                <description>
                    <![CDATA[ About a year back, I was just about ready to release Caer, a Computer Vision library in Python that would be publicly available on PyPi. But first, I decided to send it to a friend in Alberta to tinker around with it. A few days later, I found that h... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-you-should-start-using-docker-now/</link>
                <guid isPermaLink="false">66d45f3f4a7504b7409c3413</guid>
                
                    <category>
                        <![CDATA[ containers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Docker ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jason ]]>
                </dc:creator>
                <pubDate>Wed, 17 Nov 2021 20:42:19 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/why-use-docker-image.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>About a year back, I was just about ready to release <a target="_blank" href="https://github.com/jasmcaus/caer">Caer</a>, a Computer Vision library in Python that would be publicly available on PyPi. But first, I decided to send it to a friend in Alberta to tinker around with it.</p>
<p>A few days later, I found that he was still trying to figure out how to get it to work on his machine.</p>
<p>After dozens of hours, I finally found out why — Caer implemented code from the previous versions of other Python packages that simply wasn't available in their newer releases.</p>
<p>And so despite having those packages installed, my friend wasn’t able to run Caer.</p>
<p>Issues like this aren’t specific to Python packages. You might face something similar when moving locally-built code into production and not have it work because of different operating systems.</p>
<p>But what if there was a way to mitigate this issue of portability?</p>
<blockquote>
<p>Well, there is – Docker!</p>
</blockquote>
<p>Before we talk about Docker, you need to understand the intuition behind a <em>container.</em></p>
<h2 id="heading-what-is-a-container">What is a Container?</h2>
<p>A container is an entire runtime environment: an application with all its dependencies, libraries, binaries, and configuration files needed to run it, bundled up into one package.</p>
<p><img src="https://images.unsplash.com/photo-1504383633899-a17806f7e9ad?crop=entropy&amp;cs=tinysrgb&amp;fit=max&amp;fm=jpg&amp;ixid=MnwxMTc3M3wwfDF8c2VhcmNofDZ8fGNvbnRhaW5lcnxlbnwwfHx8fDE2MzY3NDEwMzM&amp;ixlib=rb-1.2.1&amp;q=80&amp;w=2000" alt="Very Blue Sky" width="2000" height="1281" loading="lazy"></p>
<p><em>Photo by [Unsplash](https://unsplash.com/@victoire_jonch?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit"&gt;Victoire Joncheray / &lt;a href="https://unsplash.com/?utm_source=ghost&amp;utm_medium=referral&amp;utm_campaign=api-credit)</em></p>
<p><em>Containerization</em> abstracts away differences in OS distributions, application dependencies, and underlying infrastructure.</p>
<h2 id="heading-containers-are-like-vms-but-way-smaller">Containers are like VMs, but way smaller</h2>
<p>With virtualization, these containers are called <em>Virtual Machines.</em> These include the operating system in addition to the application. A server running three virtual machines may have three different operating systems running on top of it.</p>
<p>Imagine how bulky this can get.</p>
<p>In contrast, you can have the same server run 3 containerized applications with Docker that all run the <em>same</em> operating system. The parts of the operating system that are shared are <em>read-only</em>, while a container has a mount (a way to access the container) for writing.</p>
<p>While VMs may be several gigabytes in size, a container may be just a few megabytes in size.</p>
<h2 id="heading-the-magic-of-containers">The magic of containers</h2>
<p>When applications are containerized, only the <em>operating system</em> is virtualized, as opposed to hardware (as is the case with VMs). Instead of provisioning hardware, a virtual OS is provisioned to the application, enabling you to run multiple applications and set resource-limitations as you please.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-42.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><a target="_blank" href="https://containerjournal.com/topics/container-ecosystems/kubernetes-vs-docker-a-primer/"><em>Source</em></a><em>: Container Journal</em></p>
<h2 id="heading-how-to-use-docker">How to Use Docker</h2>
<p>Docker is a containerization tool used that developers use to spin up isolated, reproducible environments for their applications.</p>
<p>It has a fast development process, it is easy to use, it works the same on local machines, dev, staging, and production servers, and it is extremely scalable.</p>
<p>Docker, in fact, drove the shift to the containerization of applications, and is, to no one's surprise, the most powerful player in the market today.</p>
<h4 id="heading-how-to-install-docker">How to install Docker</h4>
<ul>
<li><p>Windows or MacOS: Install <a target="_blank" href="https://www.docker.com/get-started">Docker Desktop</a></p>
</li>
<li><p>Linux: Install <a target="_blank" href="https://docs.docker.com/get-docker/">Docker</a> and <a target="_blank" href="https://docs.docker.com/compose/install/">Docker Compose</a></p>
</li>
</ul>
<p>If you are on Linux, you’ll need to run your commands as <em>root</em> or add the user to the Docker group:</p>
<pre><code class="lang-bash">sudo usermod -aG docker $(thatsme)
</code></pre>
<h2 id="heading-how-to-create-a-dockerfile">How to Create a Dockerfile</h2>
<p>In Python, to containerize an application, you will need to pack it as a Docker Image. To generate one, you need to define a Dockerfile. This name of the file is simply <strong>DOCKERFILE</strong> (no extension).</p>
<pre><code class="lang-dockerfile"><span class="hljs-comment"># Defining a base image (Python 3 in our case)</span>
<span class="hljs-keyword">FROM</span> python:<span class="hljs-number">3</span><span class="hljs-comment"># Adding a Python script to be run</span>

<span class="hljs-keyword">ADD</span><span class="bash"> hello_world_script.py /</span>

<span class="hljs-comment"># If our script uses the Caer package, we'll have to pip install it:RUN pip install caer</span>

<span class="hljs-comment"># To execute the Python script:</span>
<span class="hljs-keyword">CMD</span><span class="bash"> [ <span class="hljs-string">"python"</span>, <span class="hljs-string">"./hello_world_script.py"</span> ]</span>
</code></pre>
<ul>
<li><p><code>FROM</code> instructs Docker what image the application is based on (a mouthful, I know)</p>
</li>
<li><p><code>RUN</code> executes any additional commands (such as a pip install)</p>
</li>
<li><p><code>CMD</code> executes the commands when the image is loaded</p>
</li>
</ul>
<p>For this demonstration, I have used the <code>caer</code> package that you can install with a simple <code>pip install caer</code> .</p>
<p>Suppose, our <code>hello_world_script.py</code> script looks like this:</p>
<pre><code class="lang-python">
<span class="hljs-keyword">import</span> caer

print(caer.__version__)

img = caer.imread(<span class="hljs-string">'./img1.png'</span>)

print(img.shape) <span class="hljs-comment"># image shape</span>
print(img) <span class="hljs-comment"># image tensor</span>
</code></pre>
<p>To build the image from the Dockerfile, go ahead and run the following:</p>
<pre><code class="lang-bash">docker build -t caer-readimg .
</code></pre>
<p>Once the image has been built, you’ll be able to run it as a container.</p>
<p>You’ll also notice a ‘caer-readimg’ image (you can view all your Docker image by running the <code>docker images</code> command).</p>
<p>To run this image,</p>
<pre><code class="lang-bash">docker run caer-readimg
</code></pre>
<h2 id="heading-how-to-delete-a-docker-image">How to delete a Docker Image</h2>
<pre><code class="lang-bash"><span class="hljs-comment"># The image_id can be found when you run `docker images`</span>

docker rmi &lt;image_id&gt;
</code></pre>
<h2 id="heading-how-to-delete-a-docker-container">How to delete a Docker Container</h2>
<pre><code class="lang-bash"><span class="hljs-comment"># Retrieve the container ID:</span>
docker ps -a 

<span class="hljs-comment"># Deleting the container</span>
docker rm &lt;container_id&gt;
</code></pre>
<h1 id="heading-wrapping-up">Wrapping Up</h1>
<p>That’s how easy it is to get started with Docker. Of course, you probably don't need to build a Docker image if your application is as simple as the code discussed above – but it makes sense especially if you’re working on the same project with multiple people.</p>
<p>Be sure to <a target="_blank" href="http://twitter.com/jasmcaus">follow me on Twitter</a> for updates on future articles. Happy learning!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Python map() – List Function with Examples ]]>
                </title>
                <description>
                    <![CDATA[ Python offers a number of functional programming utilities even though it's primarily an object-oriented programming language. And the most notable one is the map() function. In this article, we'll explore what the map() function is and how to use it... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/python-map-explained-with-examples/</link>
                <guid isPermaLink="false">66d45f3bb6b7f664236cbddf</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jason ]]>
                </dc:creator>
                <pubDate>Tue, 09 Nov 2021 17:50:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/pexels-andrew-neel-2859169.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Python offers a number of functional programming utilities even though it's primarily an object-oriented programming language. And the most notable one is the map() function.</p>
<p>In this article, we'll explore what the <code>map()</code> function is and how to use it in your code.</p>
<h1 id="heading-the-map-function-in-python">The map() function in Python</h1>
<p>The <code>map()</code> function (which is a built-in function in Python) is used to apply a function to each item in an <em>iterable</em> (like a Python list or dictionary). It returns a new iterable (a <em>map object)</em> that you can use in other parts of your code.</p>
<p>The general syntax for this is:</p>
<pre><code class="lang-python">map(function, iterable, [iterable1, iterable2, ...])
</code></pre>
<p>Let's see an example: imagine you have a list of numbers, and you want to create a new list with the <em>cubes</em> of the numbers in the first list. A traditional approach would involve using the <em>for</em> loop:</p>
<pre><code class="lang-python">org_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
fin_list = []

<span class="hljs-keyword">for</span> num <span class="hljs-keyword">in</span> org_list:
    fin_list.append(num**<span class="hljs-number">3</span>)

print(fin_list) <span class="hljs-comment"># [1, 8, 27, 64, 125]</span>
</code></pre>
<p>which is perfectly valid, but let's see how using the <code>map()</code> function simplifies your code:</p>
<pre><code class="lang-python">org_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]

<span class="hljs-comment"># define a function that returns the cube of `num`</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">cube</span>(<span class="hljs-params">num</span>):</span>
    <span class="hljs-keyword">return</span> num**<span class="hljs-number">3</span>

fin_list = list(map(cube, org_list))
print(fin_list) <span class="hljs-comment"># [1, 8, 27, 64, 125]</span>
</code></pre>
<p>Don't know about you, but I find this to be much cleaner logic.</p>
<blockquote>
<p>In case you're wondering what went on behind the scenes, the <code>map()</code> function essentially iterated through each element of the iterable (in our case, <code>org_list</code>) and applied the cube function on it. It finally returned a new iterable (<code>fin_list</code> ) with the result.</p>
</blockquote>
<h2 id="heading-how-to-use-lambda-expressions-in-python">How to Use Lambda Expressions in Python</h2>
<p>Instead of writing a separate function to calculate the cube of a number, we can use a <em>lambda</em> expression in its place. Here's how you'd do that:</p>
<pre><code class="lang-python">fin_list = list(map(<span class="hljs-keyword">lambda</span> x:x**<span class="hljs-number">3</span>, org_list))
print(fin_list) <span class="hljs-comment"># [1, 8, 27, 64, 125]</span>
</code></pre>
<p>Much cleaner, wouldn't you agree?</p>
<h2 id="heading-how-to-use-built-in-functions-in-python">How to Use Built-in Functions in Python</h2>
<p>You can also pass in built-in Python functions. For example if you had a list of strings, you can easily create a new list with the length of each string in the list.</p>
<pre><code class="lang-python">org_list = [<span class="hljs-string">"Hello"</span>, <span class="hljs-string">"world"</span>, <span class="hljs-string">"freecodecamp"</span>]
fin_list = list(map(len, org_list))
print(fin_list) <span class="hljs-comment"># [5, 5, 12]</span>
</code></pre>
<h2 id="heading-how-to-use-functions-with-multiple-iterables-in-python">How to Use Functions with Multiple Iterables in Python</h2>
<p>So far we've passed into <code>map()</code> functions that take only one argument (recall the <code>cube(num)</code>). But what if your function takes in multiple arguments? An example of this would be the <code>pow(x, y)</code> function that takes in 2 arguments (it returns the result of x^y).</p>
<p>To apply a function with multiple arguments, simply pass in another iterable name following the first one.</p>
<pre><code class="lang-python">base = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]
power = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]

result = list(map(pow, base, power))
print(result) <span class="hljs-comment"># [1, 4, 27, 256]</span>
</code></pre>
<h1 id="heading-wrapping-up">Wrapping Up</h1>
<p>In this article, you've learned how to work with the <code>map()</code> function in Python. You also saw how it can dramatically reduce the size of your code, making it more readable and bug-free.</p>
<p>You should now be comfortable working with <code>map()</code> using built-in functions, lambda expressions, and even your own custom function!</p>
<p>Be sure to <a target="_blank" href="http://twitter.com/jasmcaus">follow me on Twitter</a> for updates on future articles. Have a nice one!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Python Sets – Operations and Examples ]]>
                </title>
                <description>
                    <![CDATA[ If you're a beginner to Python, chances are you've come across lists. But have you heard about sets in Python? In this tutorial, we'll explore what sets are, how to create them, and the different operations you can use on them. What are sets in Pytho... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/python-set-operations-explained-with-examples/</link>
                <guid isPermaLink="false">66d45f3d47a8245f78752a5e</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sets ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Jason ]]>
                </dc:creator>
                <pubDate>Thu, 28 Oct 2021 18:17:35 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/10/python-sets-article-image.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you're a beginner to Python, chances are you've <a target="_blank" href="https://www.freecodecamp.org/news/lists-in-python-comprehensive-guide/">come across lists</a>. But have you heard about sets in Python?</p>
<p>In this tutorial, we'll explore what sets are, how to create them, and the different operations you can use on them.</p>
<h1 id="heading-what-are-sets-in-python">What are sets in Python?</h1>
<p>In Python, sets are exactly like lists except for the fact that their elements are <em>immutable</em> (that means you cannot change/mutate an element of a set once declared). However, you can add/remove elements from the set.</p>
<p>If that was confusing, let me try and summarize:</p>
<blockquote>
<p>A set is a mutable, unordered group of elements, where the elements themselves are immutable.</p>
</blockquote>
<p>Another characteristic of a set is that it may include elements of different types. This means you can have a group of numbers, strings, and even tuples, all in the same set!</p>
<h1 id="heading-how-to-create-a-set">How to Create a Set</h1>
<p>The most common way of creating a set in Python is by using the built-in <code>set()</code> function.</p>
<pre><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>first_set = set((<span class="hljs-string">"Connor"</span>, <span class="hljs-number">32</span>, (<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)))
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set
{<span class="hljs-number">32</span>, <span class="hljs-string">'Connor'</span>, (<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)}
<span class="hljs-meta">&gt;&gt;&gt; </span>
<span class="hljs-meta">&gt;&gt;&gt; </span>second_set = set(<span class="hljs-string">"Connor"</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>second_set
{<span class="hljs-string">'n'</span>, <span class="hljs-string">'C'</span>, <span class="hljs-string">'r'</span>, <span class="hljs-string">'o'</span>}
</code></pre>
<p>You can also create sets using the curly brace <code>{}</code> syntax:</p>
<pre><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>third_set = {<span class="hljs-string">"Apples"</span>, (<span class="hljs-string">"Bananas"</span>, <span class="hljs-string">"Oranges"</span>)}
<span class="hljs-meta">&gt;&gt;&gt; </span>type(third_set)
&lt;<span class="hljs-class"><span class="hljs-keyword">class</span> '<span class="hljs-title">set</span>'&gt;</span>
</code></pre>
<p>The <code>set()</code> function takes in an <em>iterable</em> and yields a list of objects which will be inserted into the set. The <code>{}</code> syntax places the objects themselves into the set.</p>
<p>As you've probably realized, whether you use the <code>set()</code> function or the <code>{}</code> to create a set, each element needs to be an immutable object. So if you add a list (which is a mutable object) to a set, you'll run into an error:</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>incorrect_set = {<span class="hljs-string">"Apples"</span>, [<span class="hljs-string">"Bananas"</span>, <span class="hljs-string">"Oranges"</span>]}
Traceback (most recent call last):
  File <span class="hljs-string">"&lt;stdin&gt;"</span>, line <span class="hljs-number">1</span>, <span class="hljs-keyword">in</span> &lt;module&gt;
TypeError: unhashable type: <span class="hljs-string">'list'</span>
</code></pre>
<h1 id="heading-how-to-add-or-remove-elements-in-a-set">How to Add or Remove Elements in a Set</h1>
<p>We already know that sets are mutable. This means you can add/remove elements in a set.</p>
<p>Here's an example of adding elements to a set using the <code>update()</code> function.</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>add_set = set((<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>add_set
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>add_set.update((<span class="hljs-number">1</span>,))
<span class="hljs-meta">&gt;&gt;&gt; </span>add_set
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>add_set.update((<span class="hljs-string">"cello"</span>, <span class="hljs-string">"violin"</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>add_set
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-string">'violin'</span>, <span class="hljs-string">'cello'</span>}
</code></pre>
<p>But notice how nothing changes when we try to add "cello" to the set again:</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>add_set.update((<span class="hljs-string">"cello"</span>,))
<span class="hljs-meta">&gt;&gt;&gt; </span>add_Set
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-string">'violin'</span>, <span class="hljs-string">'cello'</span>}
</code></pre>
<p>This is because sets in Python <em>cannot</em> contain duplicates. So, when we tried to add <code>"cello"</code> again to the set, Python recognized we were trying to add a duplicate element and didn't update the set. This is one caveat that differentiates sets from lists.</p>
<p>Here's how you would remove elements from a set:</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>sub_set = add_set
<span class="hljs-meta">&gt;&gt;&gt; </span>sub_set.remove(<span class="hljs-string">"violin"</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>sub_set
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-string">'cello'</span>}
</code></pre>
<p>The <code>remove(x)</code> function removes the element <code>x</code> from a set. It returns a <code>KeyError</code> if <code>x</code> is not part of the set:</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>sub_set.remove(<span class="hljs-string">"guitar"</span>)
Traceback (most recent call last):
  File <span class="hljs-string">"&lt;stdin&gt;"</span>, line <span class="hljs-number">1</span>, <span class="hljs-keyword">in</span> &lt;module&gt;
KeyError: <span class="hljs-string">'guitar'</span>
</code></pre>
<p>There are a couple of other ways to remove an element(s) from a set:</p>
<ul>
<li><p>the <code>discard(x)</code> method removes <code>x</code> from the set, but <em>doesn't</em> raise any error if <code>x</code> is not present in the set.</p>
</li>
<li><p>the <code>pop()</code> method removes and returns a random element from the set.</p>
</li>
<li><p>the <code>clear()</code> method removes all elements from a set</p>
</li>
</ul>
<p>Here are some examples to illustrate:</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>m_set = set((<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>
<span class="hljs-meta">&gt;&gt;&gt; </span>m_set.discard(<span class="hljs-number">5</span>) <span class="hljs-comment"># no error raised even though '5' is not present in the set</span>
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>m_set.pop()
<span class="hljs-number">4</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>m_set
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>m_set.clear()
<span class="hljs-meta">&gt;&gt;&gt; </span>m_set
set()
</code></pre>
<h1 id="heading-python-set-operations">Python set() Operations</h1>
<p>If you remember your basic high school math, you'll probably recall mathematical set operations like <em>union</em>, <em>intersection</em>, <em>difference</em> and <em>symmetric difference</em>. Well, you can achieve the same thing with Python sets.</p>
<h2 id="heading-1-set-union">1. Set Union</h2>
<p>The union of two sets is the set of <em>all the elements</em> of both the sets without duplicates. You can use the <code>union()</code> method or the <code>|</code> syntax to find the union of a Python set.</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>first_set = {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>second_set = {<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set.union(second_set)
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set | second_set     <span class="hljs-comment"># using the `|` operator</span>
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>}
</code></pre>
<h2 id="heading-2-set-intersection">2. Set Intersection</h2>
<p>The intersection of two sets is the set of <em>all the common elements</em> of both the sets. You can use the <code>intersection()</code> method of the <code>&amp;</code> operator to find the intersection of a Python set.</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>first_set = {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>second_set = {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set.intersection(second_set)
{<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set &amp; second_set     <span class="hljs-comment"># using the `&amp;` operator</span>
{<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
</code></pre>
<h2 id="heading-3-set-difference">3. Set Difference</h2>
<p>The difference between two sets is the set of all the elements in first set that <em>are not</em> present in the second set. You would use the <code>difference()</code> method or the <code>-</code> operator to achieve this in Python.</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>first_set = {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>second_set = {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set.difference(second_set)
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set - second_set     <span class="hljs-comment"># using the `-` operator</span>
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>second_set - first_set
{<span class="hljs-number">8</span>, <span class="hljs-number">9</span>, <span class="hljs-number">7</span>}
</code></pre>
<h2 id="heading-4-set-symmetric-difference">4. Set Symmetric Difference</h2>
<p>The symmetric difference between two sets is the set of all the elements that are <em>either in</em> the first set <em>or</em> the second set <em>but not in both</em>.</p>
<p>You have the choice of using either the <code>symmetric_difference()</code> method or the <code>^</code> operator to do this in Python.</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>first_set = {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>second_set = {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set.symmetric_difference(second_set)
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>first_set ^ second_set     <span class="hljs-comment"># using the `^` operator</span>
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
</code></pre>
<h1 id="heading-how-to-modify-a-set-by-operations">How to Modify a Set by Operations</h1>
<p>Each of the <code>set()</code> operations that we discussed above can be used to <em>modify</em> an existing Python set. Similar to how you would use an augmented assignment syntax such as <code>+=</code> or <code>*=</code> to update a variable, you can do the same for sets:</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>a = {<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>b = {<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>a.update(b)          <span class="hljs-comment"># a "union" operation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>a
{<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>a &amp;= b               <span class="hljs-comment"># the "intersection" operation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>a
{<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>a -= set((<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>))  <span class="hljs-comment"># the "difference" operation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>a
{<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>}
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>a ^= b               <span class="hljs-comment"># the "symmetric difference" operation</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>a
{<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>}
</code></pre>
<h1 id="heading-other-set-operations-in-python">Other Set Operations in Python</h1>
<p>These are not so common, but they're useful in seeing how sets relate to others.</p>
<ul>
<li><p>the <code>a.issubset(b)</code> method or <code>&lt;=</code> operator returns true if the <code>a</code> is a <em>subset</em> of <code>b</code></p>
</li>
<li><p>the <code>a.issuperset(b)</code> method or <code>&gt;=</code> operator returns true if the <code>a</code> is a <em>superset</em> of <code>b</code></p>
</li>
<li><p>the <code>a.isdisjoint(b)</code> method return true if there are <em>no common elements</em> between sets <code>a</code> and <code>b</code></p>
</li>
</ul>
<h1 id="heading-frozen-sets-in-python">Frozen Sets in Python</h1>
<p>Because sets are mutable, they are unhashable – which means you cannot use them as dictionary keys.</p>
<p>Python allows you to work around this by using a <code>frozenset</code> instead. This has all the properties of a set, except that it is <em>immutable</em> (this means that you cannot add/remove elements from the frozenset). It is also hashable, so it can be used as keys to a dictionary.</p>
<p>The <code>frozenset</code> datatype has all the methods of a set (such as <code>difference()</code>, <code>symmetric_difference</code>, and <code>union</code>) but because it is immutable, it doesn't have methods to add/remove elements.</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>a = frozenset((<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>b = frozenset((<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>))
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>a.issubset(b)
<span class="hljs-literal">False</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>a.update(b)    <span class="hljs-comment"># raises an error</span>
Traceback (most recent call last):
  File <span class="hljs-string">"&lt;stdin&gt;"</span>, line <span class="hljs-number">1</span>, <span class="hljs-keyword">in</span> &lt;module&gt;
AttributeError: <span class="hljs-string">'frozenset'</span> object has no attribute <span class="hljs-string">'update'</span>
</code></pre>
<p>And using <code>frozenset</code>s as dictionary keys is as simple as 1, 2, 3:</p>
<pre><code class="lang-py"><span class="hljs-meta">&gt;&gt;&gt; </span>a = frozenset((<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>b = frozenset((<span class="hljs-string">"w"</span>, <span class="hljs-string">"x"</span>, <span class="hljs-string">"y"</span>, <span class="hljs-string">"z"</span>))
&gt;&gt;&gt;
<span class="hljs-meta">&gt;&gt;&gt; </span>d = {a: <span class="hljs-string">"hello"</span>, b: <span class="hljs-string">"world"</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>d
{frozenset({<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>}): <span class="hljs-string">'hello'</span>, frozenset({<span class="hljs-string">'w'</span>, <span class="hljs-string">'x'</span>, <span class="hljs-string">'y'</span>, <span class="hljs-string">'z'</span>}): <span class="hljs-string">'world'</span>}
</code></pre>
<h1 id="heading-wrapping-up">Wrapping Up</h1>
<p>That's it! You've learned about what sets are, how to create and work with them, and different operations you can use on them.</p>
<p>With sets done, you should now be comfortable with most of Python built-in functions. All you need to do now is practice. Good luck!</p>
<p>Be sure to <a target="_blank" href="http://twitter.com/jasmcaus">follow me on Twitter</a> for more updates. Have a nice one!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
