<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Juan Almanza</title>
    <description>The latest articles on DEV Community by Juan Almanza (@scidroid).</description>
    <link>https://dev.to/scidroid</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F576468%2Fb6a19132-3705-4a6a-bc29-1004c9cd725c.png</url>
      <title>DEV Community: Juan Almanza</title>
      <link>https://dev.to/scidroid</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/scidroid"/>
    <language>en</language>
    <item>
      <title>Your site is probably illegal</title>
      <dc:creator>Juan Almanza</dc:creator>
      <pubDate>Sat, 05 Feb 2022 04:59:32 +0000</pubDate>
      <link>https://dev.to/scidroid/your-site-is-probably-illegal-i9n</link>
      <guid>https://dev.to/scidroid/your-site-is-probably-illegal-i9n</guid>
      <description>&lt;p&gt;Privacy on the internet is a serious issue as developers we have the responsibility to respect it, this includes things like using secure communication protocols such as HTTPS as well as how and where you store user information.&lt;/p&gt;

&lt;p&gt;But something that many of us don't think about are the analytics, which in some part are sensitive information of our users and around the world there are laws that regulate it, in this article we will talk a little about why analytics can make your site break the law, what alternatives we have, and how we can implement secure analytics on your website.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why analytics can make your site break the law?
&lt;/h2&gt;

&lt;p&gt;Analytics are a great way to improve your website, by tracking pageviews, unique visitors, and other statistics you can get a better understanding of how your site is being used and make necessary changes.&lt;/p&gt;

&lt;p&gt;But while analytics are a great tool, they can also be used to track and spy on users, which can be a privacy concern. This is why many countries have laws regulating the use of analytics, in the European Union the &lt;a href="https://ec.europa.eu/info/law/law-topic/data-protection"&gt;General Data Protection Regulation (GDPR)&lt;/a&gt; is a law that regulates the use of analytics and other forms of data collection.&lt;/p&gt;

&lt;h3&gt;
  
  
  What are the requirements of GDPR?
&lt;/h3&gt;

&lt;p&gt;The GDPR requires that websites get user consent before collecting any data, this includes things like cookies, analytics, and social media buttons. User consent must be explicit, meaning that the user has to actively agree to have their data collected, it cannot be implied or assumed.&lt;/p&gt;

&lt;p&gt;Widely used services such as Google Analytics do not comply with these laws so in our sites we must add things like cookies banners and in &lt;a href="https://noyb.eu/en/austrian-dsb-eu-us-data-transfers-google-analytics-illegal"&gt;some countries these services become illegal&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GBKD9JuK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/MxoVzg4Y1a5ePfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GBKD9JuK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/MxoVzg4Y1a5ePfj.png" alt="Cookie Banner Example" width="599" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And user data must be protected, it must be stored in a secure manner and be accessible only by authorized personnel. If a website doesn't comply with the GDPR they can be fined up to 4% of their global annual revenue or €20 million (whichever is greater), so it's important to understand and comply with the requirements of the GDPR.&lt;/p&gt;

&lt;h2&gt;
  
  
  What alternatives do we have?
&lt;/h2&gt;

&lt;p&gt;If you want to collect analytics data but don't want to break the law, there are a few alternatives you can use.&lt;/p&gt;

&lt;p&gt;One alternative is to use a third-party analytics provider, these providers are GDPR compliant and will ensure that your data is collected and stored in a secure manner.&lt;/p&gt;

&lt;h3&gt;
  
  
  Splitbee
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N_oAgbTa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/Tj32fSqM6dPGunl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N_oAgbTa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/Tj32fSqM6dPGunl.png" alt="Splitbee" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Splitbee is my favourite analytics service and the one this site uses, not only is it privacy-friendly and GDPR compliant, it also allows you to create conversion funnels, get real-time analytics, manage events easily, do A/B tests and create automations like sending emails every time an action is executed (which is what I use in my contact form).&lt;/p&gt;

&lt;p&gt;Plus it allows you to do all this in it's free layer with 2.500 events which also makes it ideal for blogs and small sites, and if your site moves more traffic you can upgrade to a paid plan that allows you to have much more information about your visitors.&lt;/p&gt;

&lt;p&gt;In this blog we will also learn how to integrate it into your Next.js site so you can use it quickly.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://slitbee.io"&gt;visit their site here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fathom
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--haN_ZII---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/ZsYo5GqUu7NTLnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--haN_ZII---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/ZsYo5GqUu7NTLnw.png" alt="Fathom screenshot" width="800" height="785"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fathom does not have a free version, but it is still a very solid option since paying 14 dollars you can register up to 100.000 views. It has a simple interface, but does not include automations, experiments, user profiles and more that Splitbee does, I recommend this service if you want something as simple as possible.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://usefathom.com/ref/8C8RPY"&gt;try it here with 10 dollars free credit&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Analytics
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E5YIZn2m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/WEnyloexdTPNAUc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E5YIZn2m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/WEnyloexdTPNAUc.png" alt="Simple Analytics dashboard" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simple Analytics is another alternative, this one is a bit more expensive than fathom with a basic plan starting from 19 dollars, but this one allows you to have analytics on as many sites as you want, plus it has some interesting features like knowing from which tweets your visits come from. otherwise it is very similar to Fathom.&lt;/p&gt;

&lt;p&gt;You can &lt;a href="https://simpleanalytics.com/"&gt;try it here&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Another alternative is to use a tool with server-side analytics like &lt;a href="https://www.netlify.com/products/analytics/"&gt;Netlify Analytics&lt;/a&gt;, this tool allows you to collect analytics data without using cookies or other tracking technologies.&lt;/p&gt;

&lt;p&gt;And finally, you can also use a tool like &lt;a href="https://matomo.org/"&gt;Matomo&lt;/a&gt;, which is an open source analytics tool that you can host on your own server and configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing Splitbee in a Next.js site
&lt;/h2&gt;

&lt;p&gt;Now let's make a small Splitbee example in Next.js. &lt;/p&gt;

&lt;p&gt;Before we start we just need to create an account, you can go directly by &lt;a href="https://app.splitbee.io/"&gt;clicking here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OnTZX-Aw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/Q6mtiKJ81y7Ppf2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OnTZX-Aw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/Q6mtiKJ81y7Ppf2.png" alt="Splitbee login" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we have registered we must create a new project, just put a name and a url, and we would have everything ready in this part.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iMy1fnbT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/rTSPmA3g81lxKYn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iMy1fnbT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/rTSPmA3g81lxKYn.png" alt="New project page" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we have a project let's start with the code.&lt;/p&gt;




&lt;p&gt;First we must install the packages we need.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add @splitbee/web

// or

npm &lt;span class="nb"&gt;install&lt;/span&gt; @splitbee/web
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will use one of the functions of Next that will allow us to make a kind of proxy by allowing us to make routes in our site that redirect to another part, in this case we will do it to store the script and the endpoint of the API in our own site.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// next.config.js&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rewrites&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/sb.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://cdn.splitbee.io/sb.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/_hive/:slug&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;destination&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://hive.splitbee.io/:slug&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;rewrites&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will create a special Next file that will allow us to add the Splitbee script to all the pages of our site.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// pages/_app.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;splitbee&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@splitbee/web&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pageProps&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;splitbee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;scriptUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/sb.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;apiUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/_hive&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Component&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;pageProps&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now we have everything ready, and with this we can have statistics of visitors to our site, including the countries from which they visit us, the number of views, even from what website our users came from.&lt;/p&gt;

&lt;p&gt;And if we visit our Splitbee panel we will be able to see something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wAGJ2WvG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/cfRAsdvrUZSOHzl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wAGJ2WvG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/cfRAsdvrUZSOHzl.png" alt="Splitbee panel" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Other features
&lt;/h3&gt;

&lt;p&gt;Splitbee in addition to all the above mentioned allows us to manage events and store user data, now we will learn how to use them.&lt;/p&gt;

&lt;p&gt;First we will make a function that will allow us to handle events, which is nothing more than an indicator that an action was performed, which we can give a name and other additional values.&lt;/p&gt;

&lt;p&gt;In the second function we will be able to add parameters to the users, for example in the analytics page we can identify the actions of our users by being able to relate them with their names, as in the example below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TCJq_NK7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/LBCNz47hIRMyind.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TCJq_NK7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/LBCNz47hIRMyind.png" alt="User Example" width="460" height="392"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// utils/analytics.js&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;splitbee&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@splitbee/web&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Events&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;trackEvent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;splitbee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;track&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;details&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Save user data&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setUser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;splitbee&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this can be implemented in different ways, here are some examples:&lt;/p&gt;

&lt;h4&gt;
  
  
  Record event at button press
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;trackEvent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utils/analytics&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ButtonWithEvent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;trackEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Button clicked&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Define user when filling out a form
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;setUser&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;utils/analytics&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SignUpForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;setUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"submit"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the end, by mixing events and setting user data we can have very complete navigation statistics as seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mPY4aNCb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/qhogI2cW8i1bYfH.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mPY4aNCb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s2.loli.net/2022/02/05/qhogI2cW8i1bYfH.png" alt="Splitbee user dashboard" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>nextjs</category>
      <category>react</category>
      <category>analytics</category>
    </item>
    <item>
      <title>An introduction to Git: My first commit</title>
      <dc:creator>Juan Almanza</dc:creator>
      <pubDate>Wed, 09 Jun 2021 20:09:08 +0000</pubDate>
      <link>https://dev.to/scidroid/an-introduction-to-git-my-first-commit-45b1</link>
      <guid>https://dev.to/scidroid/an-introduction-to-git-my-first-commit-45b1</guid>
      <description>&lt;h2&gt;
  
  
  What is Git?
&lt;/h2&gt;

&lt;p&gt;Git is a version control system initially created by Linus Torvalds, the same creator of the Linux kernel. Git was born when the linux kernel used a version control system called BitKeeper, but this was proprietary (or closed source) and when the kernel contributors decided to look at other systems they found that none of the alternatives at the time were sufficient.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G0jcBpDz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kulqu1vmzdkaj6h11ua.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G0jcBpDz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2kulqu1vmzdkaj6h11ua.jpg" alt="Linux Trovalds" width="800" height="476"&gt;&lt;/a&gt;&lt;br&gt;
Git allows us to manage, distribute and collaborate on our code so that it is organized and there is an efficient workflow when programming with several people, it will also help us to do things like going back to previous versions of our project, or see what the other people who collaborate on our project have programmed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing Git
&lt;/h2&gt;

&lt;p&gt;You can install Git on your computer in several ways, the easiest is if you have a package manager, such as aptitude, &lt;a href="https://brew.sh/"&gt;brew&lt;/a&gt; or &lt;a href="https://chocolatey.org/"&gt;chocolatey&lt;/a&gt;.&lt;br&gt;
if you have some of these just run this line in your terminal, if you are on linux or MacOS and it does not work correctly you can run it with the &lt;code&gt;sudo&lt;/code&gt; instruction at the beginning of the command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;{&lt;/span&gt; apt | brew | choco &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if you do not have package managers installed you can see these tutorials to do it in windows:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/E6-YSidPCu0"&gt;
&lt;/iframe&gt;
&lt;br&gt;
and also for linux and MacOS:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/y2xkghn2X00"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's start with Git
&lt;/h2&gt;

&lt;p&gt;To start let's create a folder, and open that folder in the terminal, then we must initialize our repository, for that we execute the command &lt;code&gt;git init&lt;/code&gt; and it should say that the repository has been initialized and now we can start managing versions in our code.&lt;br&gt;
To start executing commands we are going to create a code example, in this case an HTML document where we are going to create a Christmas wishlist.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Wishlist&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Wish List for christmas&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Be a superhero&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Buy a Mansion with my junior salary&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;visit the &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://scidroid.me"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;SciDroid's Web&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we save this file we can make a commit, which will allow us to save the changes in this file. let's see the example.&lt;br&gt;
The first thing we will do is to add the file to git, for this we will do the following command &lt;code&gt;git add index.html&lt;/code&gt;&lt;br&gt;
This command will make git start checking the changes in our file, and the last step before making our first commits is to execute these commands to identify ourselves.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"John Doe"&lt;/span&gt;
git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email johndoe@example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just change the name and email to your name and email address.&lt;br&gt;
Now the last part is to make a commit, just run the following command and change the message to the one you like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"message"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and if everything went well, congratulations you have done your first commit, now keep learning because git is an essential tool in development.&lt;br&gt;
Thanks for reading.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>git</category>
    </item>
    <item>
      <title>Our computers run on sand, a post about silicon.</title>
      <dc:creator>Juan Almanza</dc:creator>
      <pubDate>Tue, 18 May 2021 23:22:20 +0000</pubDate>
      <link>https://dev.to/scidroid/our-computers-run-on-sand-a-post-about-silicon-497h</link>
      <guid>https://dev.to/scidroid/our-computers-run-on-sand-a-post-about-silicon-497h</guid>
      <description>&lt;h2&gt;
  
  
  Sand?
&lt;/h2&gt;

&lt;p&gt;Yes, although it seems incredible what I am saying our economy works with sand. well, not exactly, it is a component of sand called &lt;strong&gt;silicon&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fsand.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fsand.jpg" alt="Sand"&gt;&lt;/a&gt; &lt;strong&gt;Sand, Photo by &lt;a href="https://www.pexels.com/@louis-965146" rel="noopener noreferrer"&gt;Louis&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Silicon?
&lt;/h3&gt;

&lt;p&gt;Silicon is the most abundant chemical element in the world, this is formed in the megastars when two oxygen atoms are joined and when they explode in a supernova they spread all over the universe, this is the aspect of silicon.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fsilicon.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fsilicon.jpg" alt="Silicon"&gt;&lt;/a&gt; &lt;strong&gt;Silicon, Photo by &lt;a href="https://www.freeimages.com/es/photographer/greschoj-64534" rel="noopener noreferrer"&gt;greschoj&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Maybe at this moment you are saying &lt;strong&gt;&lt;em&gt;"That cannot be the most abundant element in the world, I have never seen that in my life"&lt;/em&gt;&lt;/strong&gt;, but it is because it is a block of pure silicon, the most common way to find it is in sand, this because it is a substance that does not corrode easily and with the passage of time most of the components of the sand go away but the silicon remains, well not exactly silicon, what really remains is silicon dioxide which is a mixture between silicon and oxygen, better known as quartz, and this is another very common way to find it, because normally this is found in forests as a kind of white rock that is found between stones or loose as crystals that are geometrically perfect and very transparent. In addition, silicon forms the silicates, some of which are the base of the terrestrial mantle, which makes it the most abundant material on the planet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is it important?
&lt;/h3&gt;

&lt;p&gt;Silicon is important because it is the base of modern computing, which is why the most famous place for technology is called Silicon Valley. Its uses are very varied, have you ever played Minecraft or have you heard that if you melt sand you can make glass, this is because of the silicon dioxide that is in the sand, even make laser beams, or even the silicon that is used in breast augmentation and other procedures, the usefulness of silicon is almost infinite but what we are interested in is its use in technology.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the silicon is used in tech?
&lt;/h2&gt;

&lt;p&gt;For this we are going to talk a little bit about the history of computing. Before, we had the abacus, which allowed us to do basic operations, but everything developed until we were able to make mechanical computers that allowed automatic operations, until we needed to make really complex calculations and vacuum tube computers were invented.&lt;/p&gt;

&lt;p&gt;But they were enormous, so transistor-based computers were created, which is a small electrical circuit with which we can control whether or not electricity passes through, but with the passage of time we needed more and more power, and we discovered that we could take silicon and make millions of microscopic transistors inside and thus microprocessors were born.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fchips.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fchips.jpg" alt="MicroChips"&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;MicroChips, Photo by &lt;a href="https://www.pexels.com/@shellystill" rel="noopener noreferrer"&gt; Shelly&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How do you transform sand into processors?
&lt;/h3&gt;

&lt;p&gt;The process is very complicated and very delicate to levels that something badly done can damage the chip completely, The first thing is to obtain pure silicon, this is usually done by taking the quartz and separating the silicon from the oxygen, you can use elements such as carbon.&lt;/p&gt;

&lt;p&gt;When you have the pure silicon you must crystallize it, and with a very delicate process to cut it, if you cut it badly it is possible that it breaks and it must have a thickness of a few millimeters, when it is ready the most difficult part arrives, a process called photolithography is made where the transistors are printed in the silicon wafer, and you must pass it through complex chemical and physical processes, in a wafer millions of transistors fit and according to the law of Moore every two years the amount of transistors that can fit in a chip doubles.&lt;/p&gt;

&lt;p&gt;But, we reach a point where it is increasingly difficult to make them smaller and it is a constant challenge for the creators of microprocessors.&lt;/p&gt;

&lt;p&gt;When a wafer is finished it looks like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fplate.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fyohago.tech%2Fassets%2Fimg%2Fsample%2Fplate.jpg" alt="Silicon Wafer"&gt;&lt;/a&gt; &lt;strong&gt;Silicon Wafer, Photo by &lt;a href="https://pixabay.com/users/fabersam-98886/" rel="noopener noreferrer"&gt;fabersam&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then it is only cut to make way for microprocessors.&lt;/p&gt;

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

&lt;p&gt;&lt;cite&gt;Cover image by &lt;a href="https://www.pexels.com/es-es/@oksana-titova-19163191?utm_content=attributionCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=pexels" rel="noopener noreferrer"&gt;Oksana&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
    </item>
    <item>
      <title>Learning to code in Python: The Basics</title>
      <dc:creator>Juan Almanza</dc:creator>
      <pubDate>Wed, 31 Mar 2021 03:03:37 +0000</pubDate>
      <link>https://dev.to/scidroid/learning-to-code-in-python-the-basics-ib3</link>
      <guid>https://dev.to/scidroid/learning-to-code-in-python-the-basics-ib3</guid>
      <description>&lt;h2&gt;
  
  
  About Python
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2Fpython.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2Fpython.svg" alt="Python Logo"&gt;&lt;/a&gt;&lt;br&gt;
Python is a widely-used, interpreted, object-oriented, and high-level programming language with dynamic semantics, used for general-purpose programming. It was created by Guido van Rossum, and first released on February 20, 1991.&lt;/p&gt;
&lt;h3&gt;
  
  
  Why Python?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;it’s easy to learn – the time needed to learn Python is shorter than for many other languages; this means that it’s possible to start the actual programming faster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;it’s easy to teach – the teaching workload is smaller than that needed by other languages; this means that the teacher can put more emphasis on general (language-independent) programming techniques, not wasting energy on exotic tricks, strange exceptions and incomprehensible rules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;it’s easy to use for writing new software – it’s often possible to write code faster when using Python.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;it’s easy to understand – it’s also often easier to understand someone else’s code faster if it is written in Python.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;it’s easy to obtain, install and deploy – Python is free, open and multiplatform; not all languages can boast that.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  What is Python used for?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Web and Internet development (e.g., Django and Pyramid frameworks, Flask and Bottle micro-frameworks).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scientific and numeric computing (e.g., SciPy – a collection of packages for the purposes of mathematics, science, and engineering; Ipython – an interactive shell that features editing and recording of work sessions).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Education (it’s a brilliant language for teaching programming!).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Desktop GUIs (e.g., wxWidgets, Kivy, Qt).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Software Development (build control, management, and testing – Scons, Buildbot, Apache Gump, Roundup, Trac)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Business applications (ERP and e-commerce systems – Odoo, Tryton)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Games (e.g., Battlefield series, Sid Meier\’s Civilization IV…)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Websites and services (e.g., Dropbox, UBER, Pinterest, BuzzFeed…)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Text By &lt;a href="https://pythoninstitute.org/what-is-python/" rel="noopener noreferrer"&gt;Python Institute&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The Basics
&lt;/h2&gt;

&lt;p&gt;Before starting it should be clarified that this is a basic tutorial, Python is a very extensive language, for example there are an infinite number of methods in the types of data or an overwhelming amount of things we can do in Object-Oriented Programming but in this tutorial we will not see, but I will bring more tutorials with more complex things.&lt;/p&gt;

&lt;p&gt;To start programming we have to start with the basics, we will install Python, a code editor and learn the most basic things of Python.&lt;/p&gt;
&lt;h3&gt;
  
  
  Installing Python
&lt;/h3&gt;

&lt;p&gt;The first thing we must do is go to the Python website at &lt;a href="https://python.org" rel="noopener noreferrer"&gt;https://python.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the download section and download the version compatible with your computer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2Fdownloadpython.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2Fdownloadpython.png" alt="Python Downloads Section"&gt;&lt;/a&gt; &lt;strong&gt;Download Section&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you have downloaded it, just execute the file, BEFORE INSTALLING MAKE SURE THAT THE OPTION THAT SAYS &lt;em&gt;ADD TO PATH&lt;/em&gt; IS ACTIVATED.&lt;/p&gt;

&lt;p&gt;Then just press continue until it is installed.&lt;/p&gt;
&lt;h3&gt;
  
  
  Installing a code editor
&lt;/h3&gt;

&lt;p&gt;After installing Python search for Sublime Text in Google and select the option to download.&lt;/p&gt;

&lt;p&gt;When you are in the download menu you only have to select the option compatible with your operating system, when it has been downloaded you install it. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2Fdownloadsublime.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2Fdownloadsublime.PNG" alt="Download Sublime"&gt;&lt;/a&gt; &lt;strong&gt;Sublime's Download Menu&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  REPL
&lt;/h3&gt;

&lt;p&gt;The REPL is a console interface where you can enter instructions written in Python, In this case I am only going to show you the REPL to begin but we are not going to use it more after this. &lt;/p&gt;

&lt;p&gt;The first thing we must do is open our terminal.&lt;/p&gt;

&lt;p&gt;In Windows we only have to press Win+R and a pop-up menu will appear, just type cmd and press enter.&lt;/p&gt;

&lt;p&gt;To open it in MacOS, you can open the Applications folder, then Utilities and double-click on Terminal.&lt;/p&gt;

&lt;p&gt;And in Ubuntu press Alt+F2 and type "gnome-terminal" and then enter.&lt;/p&gt;

&lt;p&gt;If your operating system is not here, look on the Internet to find out how to open it.&lt;/p&gt;

&lt;p&gt;When you have the terminal open just type &lt;code&gt;python&lt;/code&gt; in Windows, OR in MacOS or Linux &lt;code&gt;python3&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you get an error on MacOS or Linux try just typing &lt;code&gt;python&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you get an error in any operating system try to reinstall Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;C:\Users\SciDroid&amp;gt;&lt;/span&gt;python
&lt;span class="go"&gt;Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&lt;/span&gt;&lt;span class="gp"&gt;&amp;gt;&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you only have to write this and something magical will happen.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;And if you did it correctly in the terminal you should get the text &lt;em&gt;Hello World&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Congratulations you have already written your first line of code, but this is nothing now let's do the real code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Python executable
&lt;/h3&gt;

&lt;p&gt;Before we start we must activate the file name view.&lt;/p&gt;

&lt;p&gt;In Windows you must go to the file explorer in the view section and activate the option called File Name Extension.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2FExtensions.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.yohago.tech%2Fimg%2FExtensions.png" alt="Activate Extensions"&gt;&lt;/a&gt; &lt;strong&gt;This is the Spanish menu, just look for the option that says File Name Extensions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create our executable we open Sublime Text, press Ctrl+N and then Ctrl+S, here you name the file followed by the extension .py and save the file in a path you remember so you can later enter that path from the terminal.&lt;/p&gt;

&lt;p&gt;When you have saved the file, open the terminal and move to the directory with the command cd.&lt;/p&gt;

&lt;p&gt;for example if your file is in the directory &lt;code&gt;C:/Users/user/downloads/index.py&lt;/code&gt; and taking into account that by default Windows leaves us in the user folder to enter the file folder we should write&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;cd downloads
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we write in our code editor the command that we write in the REPL that is&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;We save the changes with Ctrl+S and in our terminal we write &lt;code&gt;python file&lt;/code&gt; you must replace the word file by the name of your file and press enter.&lt;/p&gt;

&lt;p&gt;And if everything went correctly you should get the text "Hello World" in the terminal.&lt;/p&gt;

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

&lt;p&gt;In Python a comment is a text that is not executed and is initialized with the # symbol.&lt;/p&gt;

&lt;p&gt;This serves us for example to explain what our code does, I'll show you with an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Program that shows the text "Hello World" in the terminal
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello World&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case we use the comment to explain the function of a program, but you can write anything inside a comment.&lt;/p&gt;

&lt;p&gt;Commenting your code is always a good practice, do it whenever possible, later we will talk about documenting your code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;A variable is a space in RAM where you can save data for later use.&lt;/p&gt;

&lt;p&gt;This allows us to save very important data for the operation of a program, for example, someone's name, how many lives a character has, etc. &lt;/p&gt;

&lt;p&gt;To define a variable in Python we have the following syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;playerLifes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we see in this example we put a name to the variable then a sign = and assign a value.&lt;/p&gt;

&lt;p&gt;Now the variables have certain rules, one of them is the names, the variables cannot begin by number and cannot be put as name reserved words of the language.&lt;/p&gt;

&lt;p&gt;when naming variables it's very good practice to put a self-descriptive name to them, for example if you want to refer to the number of attempts that a person has you can put numberOfAttempts instead of number.&lt;/p&gt;

&lt;p&gt;If you are observant you may have noticed that the variable name is written in such a way that the first word is in lower case but the first letter of next the word is in upper case, this is called Camel Case and it is a good practice to use it when you have more than one word as a variable name.&lt;/p&gt;

&lt;p&gt;And now you have a superpower you can save values in variables and with the &lt;code&gt;print()&lt;/code&gt; function pass it through the screen, let's try.&lt;/p&gt;

&lt;p&gt;We are going to define a variable and then print it for this we must use &lt;code&gt;print(variable)&lt;/code&gt; changing variable by the name of the variable that we assign, then we are going to write it in code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Jhon&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and if we run it it will result in the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;Jhon
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Request text
&lt;/h3&gt;

&lt;p&gt;Now what if we want to ask the user for data?&lt;/p&gt;

&lt;p&gt;In Python there is a function called &lt;code&gt;input()&lt;/code&gt; for that.&lt;/p&gt;

&lt;p&gt;Let's make an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is your name?: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code we are asking the user to write their name, and as we see is a variable to which we say that its value is what the user enters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Exercise
&lt;/h3&gt;

&lt;p&gt;Ok now we are going to make an exercise to put in practice all that we learned, it is quite simple, what you must do is ask a user his age and then you must pass it through the screen, but the code must have comments that explain what each thing does. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ATTENTION: DO NOT GO TO THE RESULT IF YOU HAVE NOT DONE THE EXERCISE, THE ONLY WAY TO LEARN IS TO PRACTICE.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you want to see how to solve it go to the final.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Types
&lt;/h2&gt;

&lt;p&gt;Now let's talk about the data types in Python, each one has unique properties so let's see all of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Strings
&lt;/h3&gt;

&lt;p&gt;Strings are free text variables, in them we can do anything, and we have to be careful with that because it doesn't matter what a number is if it is in a string, it will be treated as if it were text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;This is a string.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All strings are enclosed in quotes, they can be double quotes (") or single quotes (').&lt;/p&gt;

&lt;p&gt;In the strings we have a special property, we can create strings that are going to be shown exactly as they are, counting line breaks, this serves us for example to place ASCII art in our scripts, for it we must place 3 double quotes (""") at the beginning and at the end.&lt;/p&gt;

&lt;p&gt;We are going to see an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;katana&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;,_._._._._._._._._|__________________________________________________________,
|_|_|_|_|_|_|_|_|_|_________________________________________________________/
                  ! &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;katana&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;if we execute this code this will be the result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;,_._._._._._._._._|__________________________________________________________,
|_|_|_|_|_|_|_|_|_|_________________________________________________________/
                  !
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Integers
&lt;/h3&gt;

&lt;p&gt;Integers are numbers that, as their name implies, are integers, that is, they do not have a decimal place. Let's see an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;integer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Floats
&lt;/h3&gt;

&lt;p&gt;Floats are very similar to integers, the only difference is that they always have a decimal place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;floating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;4.53&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should be noted that both integers and floats accept positive and negative numbers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Booleans
&lt;/h3&gt;

&lt;p&gt;Booleans are very interesting types of data because there are only 2 'True' and 'False', and as its name says it means true and false, and these are written as they come out here with the first letter in capital letters, this type of data will serve us when we talk about flow control.&lt;/p&gt;

&lt;p&gt;Let's see an example in code.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Transforming data types
&lt;/h3&gt;

&lt;p&gt;Now what happens if we have a type of data and we want to transform it into others, for that we have the following functions represented in the tables.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Function&lt;/th&gt;
&lt;th&gt;what does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;int()&lt;/td&gt;
&lt;td&gt;transforms into an integer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;float()&lt;/td&gt;
&lt;td&gt;transforms into an float&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;str()&lt;/td&gt;
&lt;td&gt;transform into an string&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These work exactly the same way when you pass them a variable and transform it into another type of data and this is especially useful when we use things like &lt;code&gt;input()&lt;/code&gt;, which you should keep in mind that anything can be transformed into a string, but only numbers within a string can be converted to float or integer.&lt;/p&gt;

&lt;p&gt;Let's make an example of how we can use this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;lives&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lifes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this little script what we do is take the variable called "lifes" which is a number in string form and transform it into an integer type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operators
&lt;/h2&gt;

&lt;p&gt;Operators are useful for many things in Python, for example you can use them to compare, do mathematical operations or make relationships, they exist of different types and let's see them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Assignment operators
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;operator&lt;/th&gt;
&lt;th&gt;use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;=&lt;/td&gt;
&lt;td&gt;assigns the value to a variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;+=&lt;/td&gt;
&lt;td&gt;adds the value to the variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-=&lt;/td&gt;
&lt;td&gt;subtracts the value of the variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*=&lt;/td&gt;
&lt;td&gt;multiplies the value to the variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;/=&lt;/td&gt;
&lt;td&gt;divides the value to the variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;**=&lt;/td&gt;
&lt;td&gt;calculates the exponent of the value of the variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;//=&lt;/td&gt;
&lt;td&gt;calculates the integer division of the value of the variable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%=&lt;/td&gt;
&lt;td&gt;returns the rest of the division of the value of the variable&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let's put an example that we want to make a script where you can place a year and your year of birth and you get how old you will be in that year.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# We will ask for the year of birth and the year in which you want to calculate your age.
&lt;/span&gt;&lt;span class="n"&gt;birth_year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What year were you born?: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;year_to_calculated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;In what year do you want to know your age?: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;# Now we show the result
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;year_to_calculate&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; your age will be &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;year_to_calculate&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;birth_year&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before you worry to see the &lt;code&gt;print(f"{var}")&lt;/code&gt; I am going to explain it to you, this is what is called in python a f-print, in this between the keys we can put variables or operations and the result of them will be printed on the screen, this saves us work and complications.&lt;/p&gt;

&lt;p&gt;And to finish this first part I challenge you to make a simple script in Python and leave it in the comments, I will be reviewing them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Answers to the exercises
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;WARNING: IF YOU HAVEN'T DONE THE EXERCISES GO BACK UPSTAIRS AND DO THEM, IF YOU DON'T DO THEM THIS TUTORIAL WILL BE USELESS.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Exercise One
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# this code asks for the user's age and then displays it on the screen.
&lt;/span&gt;
&lt;span class="c1"&gt;# We ask for the age and store it in a variable.
&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Enter your age: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# We pass on the screen the value of the variable age.
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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