<?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: Khumbo Klein Chilamwa</title>
    <description>The latest articles on DEV Community by Khumbo Klein Chilamwa (@khumbolamulungu).</description>
    <link>https://dev.to/khumbolamulungu</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%2F851797%2F172de214-f760-4200-b7b5-657727278976.png</url>
      <title>DEV Community: Khumbo Klein Chilamwa</title>
      <link>https://dev.to/khumbolamulungu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khumbolamulungu"/>
    <language>en</language>
    <item>
      <title>The Ultimate Guide to Object-Oriented Programming in Python</title>
      <dc:creator>Khumbo Klein Chilamwa</dc:creator>
      <pubDate>Tue, 11 Jul 2023 12:53:50 +0000</pubDate>
      <link>https://dev.to/khumbolamulungu/the-ultimate-guide-to-object-oriented-programming-in-python-4i36</link>
      <guid>https://dev.to/khumbolamulungu/the-ultimate-guide-to-object-oriented-programming-in-python-4i36</guid>
      <description>&lt;p&gt;Object-Oriented Programming, also known as OOP, is one of those important topics that any programmer needs to have full knowledge of. Before diving any deeper into this topic, let us define what OOP is in general and why it is a must-have skill for any programmer. OOP in Python is a method of structuring a program by bundling related properties and behaviors into individual objects. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why OOP?
&lt;/h2&gt;

&lt;p&gt;Object Oriented Programming comes with so many benefits for the programmer, some of these benefits are listed below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Makes your code reusable&lt;/li&gt;
&lt;li&gt;Makes your code clean and gives it a clear structure&lt;/li&gt;
&lt;li&gt;Makes your code easy to maintain&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The structure of OOP
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Classes
-These are user-defined data types that act as a blueprint for objects, methods, and attributes or they are containers of objects, methods, and attributes &lt;/li&gt;
&lt;li&gt;Objects
-These are instances of a class created with specifically defined data&lt;/li&gt;
&lt;li&gt;Methods 
-These are functions defined inside a class describing the behavior of objects&lt;/li&gt;
&lt;li&gt;Attributes
-These represent the state of objects in a class&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Creating our first class
&lt;/h2&gt;

&lt;p&gt;We can create a class using the &lt;strong&gt;class&lt;/strong&gt; keyword followed by the class name and a colon at the end.&lt;br&gt;
&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ClassName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;statement1&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;
    &lt;span class="n"&gt;statementN&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example1: Creating a Car class&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do &lt;code&gt;print(type(Car))&lt;/code&gt; you will get the below output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ltu84r2d0gxuejc4pim.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ltu84r2d0gxuejc4pim.png" alt=" " width="613" height="23"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Class objects
&lt;/h2&gt;

&lt;p&gt;An object is an instance of a class and it must be known that we can have as many objects as possible from a class. The process of creating a class object is also called object instantiating, you can only create an object for a class that exists.&lt;br&gt;
&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;object_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example2: Creating a class object&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;audi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;audi&lt;/code&gt; is an object for the class Car&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a class and its objects
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating a class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;span class="c1"&gt;# instantiating the Car class
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;car2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# creating attributes for instances car1 and car2
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Audi A7&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;car2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Nissan Demio&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;car2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1994&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;# printing the output
&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;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;was built in&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&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;car2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;was built in&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;car2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5stz5hu1qxad2vrtu4hq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5stz5hu1qxad2vrtu4hq.png" alt=" " width="609" height="52"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Methods
&lt;/h2&gt;

&lt;p&gt;These are functions defined inside a class describing the behavior of objects tied to that class. Methods inside a class will always take self as the first parameter.&lt;br&gt;
&lt;strong&gt;Example3: Creating methods inside a class&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating a class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# initializing method(one of the special methods)
&lt;/span&gt;    &lt;span class="c1"&gt;# called everytime an instance is created
&lt;/span&gt;    &lt;span class="c1"&gt;# takes self always
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;
    &lt;span class="c1"&gt;# normal method to return the car info   
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;carInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; was built in &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt;

&lt;span class="c1"&gt;#instantiating class objects 
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Audi A7&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;car2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Nissan Demio&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1994&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# calling the carInformation() method
&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;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;carInformation&lt;/span&gt;&lt;span class="p"&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;car2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;carInformation&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuv6evbeazft8k2ievthy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuv6evbeazft8k2ievthy.png" alt=" " width="672" height="50"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Any object has access to everything contained in the class, for example, object &lt;code&gt;car1&lt;/code&gt; has access to method &lt;code&gt;carInformation()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let us now talk about the &lt;code&gt;__init__&lt;/code&gt; or dunder init method also known as the &lt;strong&gt;constructor&lt;/strong&gt;, this method is used to initialize an instance, and the name is fixed (cannot be renamed to anything). It is inside the &lt;code&gt;__init__&lt;/code&gt; method that we define or instantiate the class attributes, apart from attributes &lt;code&gt;self&lt;/code&gt; is another parameter that &lt;code&gt;__init__&lt;/code&gt; method takes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Other special methods used in classes
&lt;/h2&gt;

&lt;p&gt;●&lt;code&gt;__str__&lt;/code&gt; is used for displaying data in a beautiful way&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating a class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;
    &lt;span class="c1"&gt;#the __str__ function for display pretty output 
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="c1"&gt;# instantiating an object
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Range Rover&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2019&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# calling the whole object
&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;car1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvze6mwflpfk29wb6x6wb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvze6mwflpfk29wb6x6wb.png" alt=" " width="567" height="27"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;●&lt;code&gt;__repr__&lt;/code&gt; is used for logging and debugging&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating a class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;
    &lt;span class="c1"&gt;#the __repr__ function for display pretty output 
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__repr__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="c1"&gt;# instantiating an object
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Range Rover&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2019&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# calling the whole object
&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;car1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4f991cubx62wo4axd59.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb4f991cubx62wo4axd59.png" alt=" " width="567" height="27"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;__str__&lt;/code&gt; and &lt;code&gt;__repr__&lt;/code&gt; do not differ much in nature&lt;/p&gt;
&lt;h2&gt;
  
  
  Class and instance variables
&lt;/h2&gt;

&lt;p&gt;As you are creating your classes you might want to work with class variables or instance variables or work with both, so how do these two differ then? The below table explains everything:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0lf4xunovr74lg0umrjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0lf4xunovr74lg0umrjj.png" alt=" " width="800" height="275"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Example4: Class variables&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating a class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# creating the class variable after class definition
&lt;/span&gt;    &lt;span class="n"&gt;maximum_speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;210 km/hr&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="c1"&gt;# initializing method(one of the special methods)
&lt;/span&gt;    &lt;span class="c1"&gt;# called everytime an instance is created
&lt;/span&gt;    &lt;span class="c1"&gt;# takes self always
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;
    &lt;span class="c1"&gt;# normal method to return the car info   
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;carInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; was built in &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt;

&lt;span class="c1"&gt;#instantiating class objects 
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Audi A7&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# calling the carInformation() method
&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;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;carInformation&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;# accessing class and instance variable using the object
&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;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;has maximum speed of&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maximum_speed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi24fbr8w3pnfch1xskkr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi24fbr8w3pnfch1xskkr.png" alt=" " width="750" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example5: Instance variables&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating the class
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# initializing method
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="c1"&gt;# 2 instance variables name and year_made
&lt;/span&gt;        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;
&lt;span class="c1"&gt;#instantiating the class object   
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Audi A7&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# car1.name and car1.year_made accesses instance variables
&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;Car name:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="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;Year made:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;car1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8cdl3lahbzepd5rbwnva.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8cdl3lahbzepd5rbwnva.png" alt=" " width="645" height="50"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Inheritance
&lt;/h2&gt;

&lt;p&gt;Inheritance in Object Oriented Programming is a concept where a new class is created using an already existing class. As you are inheriting from a class, it means you are getting the methods, and attributes of that class, in short, you are getting everything contained in that class.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why inheritance?
&lt;/h2&gt;

&lt;p&gt;Inheritance allows the reusability of code, this means that we do not have to write the same code over and over again, and we can easily reuse a method with the same or modified data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of inheritance
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Single inheritance - a child class inherits from only one parent class
&lt;strong&gt;Syntax:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ParentClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ChildClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ParentClass&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Multiple inheritance - a child class inherits from multiple parent classes
&lt;strong&gt;Syntax:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ParentClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AnotherParentClass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ChildClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ParentClass&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AnotherParentClass&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;statement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example1: Using inheritance&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# creating class variables
&lt;/span&gt;    &lt;span class="n"&gt;maximum_speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;210 km/hr&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;number_of_tyres&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
    &lt;span class="c1"&gt;# the dunder init method/initializer
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;

&lt;span class="c1"&gt;# class Minibus inheriting from class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Minibus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# __init__ method of class Minibus
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;
    &lt;span class="c1"&gt;# method to return price
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;carPrice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;
&lt;span class="c1"&gt;# instantiating the object for class Minibus
&lt;/span&gt;&lt;span class="n"&gt;minbus1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Minibus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Vanetti&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2013&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;MWK4500000&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# printing data
&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;Name:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minbus1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;#name for Minibus class
&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;Year made:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minbus1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;#year for Minibus class
&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;Maximum speeed:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minbus1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maximum_speed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;#max_speed inherited from Car
&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;Number of tyres:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minbus1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;number_of_tyres&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;#number_of_tyres inherited from Car
&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;Price:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minbus1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;carPrice&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;&lt;span class="c1"&gt;#calling the carPrice() method in Minibus
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma7kob5o98s2drkyirrq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma7kob5o98s2drkyirrq.png" alt=" " width="702" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Encapsulation
&lt;/h2&gt;

&lt;p&gt;As you are writing your programs in an Object Oriented Programming way, situations arise where you want your class data not to be modified in any way, to solve this encapsulation comes into play. Encapsulation is defined as a way of restricting access to methods and variables available in a class. Using encapsulation, you can make your class attributes private or protected.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Private - These attributes are invisible and inaccessible from outside the class itself&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__year_made&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="c1"&gt;#this attribute is private
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use double underscores &lt;code&gt;__&lt;/code&gt; to denote a private attribute&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example2: Creating a private attribute&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating our class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# initializing attribute name via __init__
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="c1"&gt;#this is a private attribute
&lt;/span&gt;
&lt;span class="c1"&gt;#instantiating an object   
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BMW&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# printing the private attribute
&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;car1&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;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnyznjvj46f27oh33yhc8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnyznjvj46f27oh33yhc8.png" alt=" " width="800" height="100"&gt;&lt;/a&gt;&lt;br&gt;
We are getting an error because the private attribute is invisible and inaccessible outside the class&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Protected - This attribute can only be accessed via a subclass but it’s possible to access them outside the class&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;year_made&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="c1"&gt;#this attribute is protected
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use a single underscore &lt;code&gt;_&lt;/code&gt; to denote a protected attribute&lt;br&gt;
&lt;strong&gt;Example3: creating a protected attribute&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating our class Car
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# initializing attribute name via __init__
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="c1"&gt;#this is a protected attribute
&lt;/span&gt;
&lt;span class="c1"&gt;#instantiating an object   
&lt;/span&gt;&lt;span class="n"&gt;car1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;BMW&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# printing the protected attribute
&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;car1&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;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vse7wkl47tt3o223530.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vse7wkl47tt3o223530.png" alt=" " width="634" height="27"&gt;&lt;/a&gt;&lt;br&gt;
To access the protected attribute outside the class, we use a single underscore before the attribute name e.g. &lt;code&gt;car1._name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;br&gt;
Attributes without any underscores are said to be public, this means they are visible and accessible even from outside the class itself using an object.&lt;/p&gt;
&lt;h2&gt;
  
  
  Polymorphism
&lt;/h2&gt;

&lt;p&gt;Poly means many and morphism means forms, so polymorphism means having many forms. In Python, polymorphism means the same function name is used in different ways.&lt;br&gt;
&lt;strong&gt;Example4: Using polymorphism&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# creating class Square
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# initializer
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;side&lt;/span&gt; 
    &lt;span class="c1"&gt;# common method
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;side&lt;/span&gt;
&lt;span class="c1"&gt;# creating class Triangle
&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Triangle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# initializer
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;
    &lt;span class="c1"&gt;# common method
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;
&lt;span class="c1"&gt;# instantiating class objects
&lt;/span&gt;&lt;span class="n"&gt;sq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tri&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Triangle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# printing results
&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;Area of square: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;calculate_area&lt;/span&gt;&lt;span class="p"&gt;())&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;Area of triangle: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tri&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;calculate_area&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygrn6j9dsc1o1fflutk7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygrn6j9dsc1o1fflutk7.png" alt=" " width="714" height="50"&gt;&lt;/a&gt;&lt;br&gt;
In our two classes, we have created a common method &lt;code&gt;calculate_area()&lt;/code&gt; that is being used in different ways, that is calculating the area of a square and a triangle. &lt;/p&gt;

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

&lt;p&gt;In summary, mastering object-oriented concepts is a must-have skill for any developer. Following an object-oriented paradigm when writing your code makes it cleaner, maintainable, and reusable.&lt;/p&gt;

</description>
      <category>oop</category>
      <category>python</category>
      <category>programming</category>
      <category>advance</category>
    </item>
    <item>
      <title>A Python Script for Downloading YouTube Videos</title>
      <dc:creator>Khumbo Klein Chilamwa</dc:creator>
      <pubDate>Fri, 10 Mar 2023 11:26:53 +0000</pubDate>
      <link>https://dev.to/khumbolamulungu/a-python-script-for-downloading-youtube-videos-5f1j</link>
      <guid>https://dev.to/khumbolamulungu/a-python-script-for-downloading-youtube-videos-5f1j</guid>
      <description>&lt;p&gt;It is no surprise that YouTube has become a great platform where you could find lots of video resources like courses, music videos, movies, etc. For a self-taught programmer like me, it has become a daily go-to resource whenever am stuck on my coding projects. On YouTube, there are a lot of exciting videos and you might want to have some of these videos on your local machine, this means that you will need a video downloader app to download them. What if I tell you that you can build your video downloader using Python? In this article, I will be showing you how you can build a Python script that will download for you YouTube videos from the ground up using a lightweight and simple-to-use library called &lt;strong&gt;&lt;a href="https://pytube.io/en/latest/" rel="noopener noreferrer"&gt;pytube&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is what we will cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installing &lt;strong&gt;pytube&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Creating the script&lt;/li&gt;
&lt;li&gt;Testing the script&lt;/li&gt;
&lt;li&gt;Conclusion &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installing pytube
&lt;/h2&gt;

&lt;p&gt;First things first, let’s install the &lt;strong&gt;pytube&lt;/strong&gt; library, in your terminal enter this command:&lt;br&gt;
&lt;code&gt;$ pip install pytube&lt;/code&gt;&lt;br&gt;
Make sure you have an internet connection as you are installing the library.&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the script
&lt;/h2&gt;

&lt;p&gt;After successfully installing the library, create a new Python file and call it &lt;strong&gt;video_downloader_script.py&lt;/strong&gt;, you can name it whatever you what as long as the name is meaningful. Do the following imports:&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="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pytube.cli&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;on_progress&lt;/span&gt; &lt;span class="c1"&gt;# this displays download progress in the console
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pytube&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;YouTube&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that the imports are taken care of, let’s create the video download handler, this is the function that will handle the video download task. Below the imports, paste this 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="c1"&gt;# this is the handler/function for downloading the video
# the function takes the video url as an argument
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;video_downloader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;video_url&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# passing the video url and progress_callback to the YouTube object
&lt;/span&gt;    &lt;span class="n"&gt;my_video&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;YouTube&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;video_url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;on_progress_callback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;on_progress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# downloading the video in high resolution
&lt;/span&gt;    &lt;span class="n"&gt;my_video&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;streams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_highest_resolution&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;download&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="c1"&gt;# return the video title
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;my_video&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To be on the same page, let’s break down the &lt;strong&gt;video_downloader()&lt;/strong&gt; function. We, first of all, pass a video URL to the function and inside it, we create a &lt;strong&gt;YouTube&lt;/strong&gt; object. This object has a lot of methods like &lt;strong&gt;streams&lt;/strong&gt;, &lt;strong&gt;get_highest_resolution&lt;/strong&gt;, &lt;strong&gt;download&lt;/strong&gt;, etc. &lt;strong&gt;streams&lt;/strong&gt; will get all the available streams for the video, &lt;strong&gt;get_highest_resolution&lt;/strong&gt; will return the highest resolution for the video and &lt;strong&gt;download&lt;/strong&gt; is for downloading the video. And the last line of the function returns the video title.&lt;/p&gt;

&lt;p&gt;Below the function add these lines of 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="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
    Running the code inside the try/except block
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# getting the url from the user
&lt;/span&gt;    &lt;span class="n"&gt;youtube_link&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 the YouTube link:&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&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;Downloading your Video, please wait.......&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# passing the url to the function
&lt;/span&gt;    &lt;span class="n"&gt;video&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;video_downloader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;youtube_link&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# printing the video title
&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="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;video&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt; downloaded successfully!!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;except&lt;/span&gt;&lt;span class="p"&gt;:&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;Failed to download video&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;Here is the breakdown of the code snippet, we have a &lt;strong&gt;try/except&lt;/strong&gt; block, inside the &lt;strong&gt;try&lt;/strong&gt; we are getting the link from the user via the &lt;strong&gt;input()&lt;/strong&gt; function. We are then printing a message to the console using the &lt;strong&gt;print()&lt;/strong&gt; function, after that, we are making a function call and passing the video link to this function. Finally, we are printing a successful message to the console.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;except&lt;/strong&gt; will run if there are errors while downloading the video. &lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the script
&lt;/h2&gt;

&lt;p&gt;It is now time we test the script, go on YouTube and copy any video link of your choice. Run the script using this command:&lt;br&gt;
&lt;code&gt;$ python video_downloader_script.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will be prompted to enter the video link, and if you enter the link this is the output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0gk3naeymq5w7hqr5i9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx0gk3naeymq5w7hqr5i9.png" alt=" " width="624" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the download is complete this is the output you will get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4drakkcq785hrf5wwqqx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4drakkcq785hrf5wwqqx.png" alt=" " width="624" height="50"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And if you check your current working directory, you will see a video file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxsn3k0hkvbe3yl23hsk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxsn3k0hkvbe3yl23hsk.png" alt=" " width="612" height="54"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose we had no internet connection, the &lt;strong&gt;except&lt;/strong&gt; statement will execute and the output would be this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2qb5ijk0vek9wpze8lc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa2qb5ijk0vek9wpze8lc.png" alt=" " width="624" height="48"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Something worth mentioning here is not every video that is downloadable on YouTube with this script, some videos require a subscription, some are restricted to a certain region, some are live streams, etc.&lt;/p&gt;

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

&lt;p&gt;That’s it, geeks!!!! I hope you have learned so much from this article. There is so much that you can do with this library, for more information do read its documentation. Thanks for reading.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>script</category>
      <category>tutorial</category>
      <category>pytube</category>
    </item>
    <item>
      <title>Building Command Line Applications using the click-shell Library</title>
      <dc:creator>Khumbo Klein Chilamwa</dc:creator>
      <pubDate>Wed, 01 Mar 2023 13:00:57 +0000</pubDate>
      <link>https://dev.to/khumbolamulungu/building-command-line-applications-using-the-click-shell-library-27n3</link>
      <guid>https://dev.to/khumbolamulungu/building-command-line-applications-using-the-click-shell-library-27n3</guid>
      <description>&lt;p&gt;The &lt;strong&gt;&lt;a href="https://click-shell.readthedocs.io/en/latest/index.html" rel="noopener noreferrer"&gt;click-shell&lt;/a&gt;&lt;/strong&gt; is a Python library that’s built on top of the standard &lt;strong&gt;cmd&lt;/strong&gt; library. It is an extension of the &lt;strong&gt;click&lt;/strong&gt; library that’s used for building command-line applications. These command-line applications are programs that use a command-line interface(CLI) for receiving commands from users. These commands are in the form of text, and they are for instructing the computer to do a specific task. One thing that’s notable about command-line applications is that they do not have a graphical user interface(GUI), it’s just the console with some background and the user is prompted to enter commands. Have you ever wondered how a popular command line application like &lt;strong&gt;Git&lt;/strong&gt; works? if you are curious and want to know how it works and you fancy the idea of building your own command line application then this tutorial is for you.&lt;/p&gt;

&lt;p&gt;These is what we will cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installing the &lt;strong&gt;click-shell&lt;/strong&gt; Library&lt;/li&gt;
&lt;li&gt;Creating the Shell&lt;/li&gt;
&lt;li&gt;Adding a Command to the Shell&lt;/li&gt;
&lt;li&gt;Getting Advanced&lt;/li&gt;
&lt;li&gt;Conclusion &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installing the click-shell Library
&lt;/h2&gt;

&lt;p&gt;To use the &lt;strong&gt;click-shell&lt;/strong&gt; library you need to install it on your machine, enter this command in your terminal:&lt;br&gt;
&lt;code&gt;$ pip install click-shell&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Creating the Shell
&lt;/h2&gt;

&lt;p&gt;Now that we have installed &lt;strong&gt;click-shell&lt;/strong&gt;, let us create a new Python file and call it &lt;strong&gt;automation_shell.py&lt;/strong&gt;. Make it look like 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="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;click_shell&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;

&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
Welcome to Ninja Shell!!!Please enter a command below.
&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="c1"&gt;# creating the shell
&lt;/span&gt;&lt;span class="nd"&gt;@shell&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ninjashell/&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;intro&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;my_shell&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="c1"&gt;# executing the shell 
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&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;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;my_shell&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 code, we are importing the &lt;strong&gt;shell&lt;/strong&gt; from &lt;strong&gt;click_shell&lt;/strong&gt;, then we are creating a string that will be the shell’s welcoming message. &lt;/p&gt;

&lt;p&gt;To create the &lt;strong&gt;shell&lt;/strong&gt;, use the &lt;strong&gt;&lt;a href="https://dev.to/khumbolamulungu/"&gt;@shell()&lt;/a&gt;&lt;/strong&gt; decorator which takes &lt;strong&gt;prompt&lt;/strong&gt; and &lt;strong&gt;intro&lt;/strong&gt; as arguments, both these arguments are strings.&lt;/p&gt;

&lt;p&gt;After the shell’s definition, create its function with a &lt;strong&gt;pass&lt;/strong&gt; statement inside, and finally, we are executing the function inside the &lt;strong&gt;if&lt;/strong&gt; block.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a Command to the Shell
&lt;/h2&gt;

&lt;p&gt;Let’s add the first command to the &lt;strong&gt;shell&lt;/strong&gt;, this command will just print a hello word text. To do that, below the &lt;strong&gt;shell&lt;/strong&gt; paste this 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="c1"&gt;# adding a command to print hello world message
&lt;/span&gt;&lt;span class="nd"&gt;@my_shell.command&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# adds a shell’s command
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello_world&lt;/span&gt;&lt;span class="p"&gt;():&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;To add a command to the &lt;strong&gt;shell&lt;/strong&gt;, use the &lt;strong&gt;command()&lt;/strong&gt; method. Create the command which is a Python function, then inside this function define what you want the command to do when executed. Note, the command that we will enter is the &lt;strong&gt;hello-world&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To run the program, use:&lt;br&gt;
&lt;code&gt;$ python automation_shell.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Make sure you get this output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqmlxpnvx6imv39ud9y0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqmlxpnvx6imv39ud9y0.png" alt=" " width="624" height="66"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter the &lt;strong&gt;hello-world&lt;/strong&gt; command and the output will be this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xcxugxl10tibvq1hqqf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xcxugxl10tibvq1hqqf.png" alt=" " width="624" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;click-shell&lt;/strong&gt; library handles so much under the hood, like exception handling and keeping the &lt;strong&gt;shell&lt;/strong&gt; running even when an error occurs and it has some inbuilt commands like the &lt;strong&gt;exit&lt;/strong&gt; command. &lt;/p&gt;

&lt;p&gt;Try to enter a command that does not exist, you will get this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwyqwzuhiscwwzqwy223m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwyqwzuhiscwwzqwy223m.png" alt=" " width="624" height="141"&gt;&lt;/a&gt;&lt;br&gt;
And to break out of the shell, just enter the exit command.&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting Advanced
&lt;/h2&gt;

&lt;p&gt;We will now modify the &lt;strong&gt;shell&lt;/strong&gt; to do meaningful tasks like listing the available &lt;strong&gt;shell&lt;/strong&gt; commands, printing the current date and time, and creating a file. Open the file and replace the current code with this 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="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;click_shell&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;shell&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;

&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
Welcome to Ninja Shell!!!Please enter a command below. If you want to
see a list of all the available commands, enter &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;help&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="c1"&gt;# creating the shell
&lt;/span&gt;&lt;span class="nd"&gt;@shell&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ninjashell/&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;intro&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;my_shell&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;pass&lt;/span&gt;

&lt;span class="c1"&gt;# adding command to the shell to list available commands
&lt;/span&gt;&lt;span class="nd"&gt;@my_shell.command&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;help&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="c1"&gt;# the command will be help
&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;Here is a list of all commands:
*******************************
help: List all the available commands
date-time: Prints current date and time
create-file: Creates a new file and write to it
exit: Exits the shell
        &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@my_shell.command&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;date_time&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="c1"&gt;# the command will be date-time
&lt;/span&gt;    &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%d/%m/%Y %H:%M:%S&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# getting the formatted current date and time
&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;The current date&amp;amp;time is: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;now&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;span class="nd"&gt;@my_shell.command&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_file&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="c1"&gt;# the command will be create-file
&lt;/span&gt;    &lt;span class="n"&gt;filename&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 the file name and extension:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# getting the filename from user
&lt;/span&gt;    &lt;span class="n"&gt;content&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 the file content:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# getting the file contents from user
&lt;/span&gt;    &lt;span class="c1"&gt;# creating the new file, opening it in write mode
&lt;/span&gt;    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;w&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# writing content to the file
&lt;/span&gt;
&lt;span class="c1"&gt;# executing the shell 
&lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&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;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;my_shell&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To be on the same page, let’s do some code breakdown. This code is not different from the previous code, here we have a few additions. &lt;/p&gt;

&lt;p&gt;We have imported the &lt;strong&gt;datetime&lt;/strong&gt; library, extended the message string, and added 3 commands, &lt;strong&gt;help&lt;/strong&gt;, &lt;strong&gt;date-time&lt;/strong&gt;, and &lt;strong&gt;create-file&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;help&lt;/strong&gt; command will list all the available commands for the &lt;strong&gt;shell&lt;/strong&gt;, the &lt;strong&gt;date-time&lt;/strong&gt; command will print the current date and time and lastly, the &lt;strong&gt;create-file&lt;/strong&gt; command will assist the user in creating a basic file. &lt;/p&gt;

&lt;p&gt;Run the program and enter the help command to get this output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6j675n698fuoprynyb8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj6j675n698fuoprynyb8.png" alt=" " width="624" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enter the &lt;strong&gt;date-time&lt;/strong&gt; command, you get this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltv978gq6lwl8klqawf9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fltv978gq6lwl8klqawf9.png" alt=" " width="578" height="68"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a file, enter the &lt;strong&gt;create-file&lt;/strong&gt; command:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3nxz4x7vec09477to4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs3nxz4x7vec09477to4a.png" alt=" " width="566" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will find the file in your current working directory:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06efh44irec3id1b16x6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F06efh44irec3id1b16x6.png" alt=" " width="564" height="56"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this content:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7extrkkp5qj10cczsjb2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7extrkkp5qj10cczsjb2.png" alt=" " width="547" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;That’s it, geeks!!! I hope you have learned so much from this piece. Remember there is so much that you could do with &lt;strong&gt;click-shell&lt;/strong&gt;. I have only shown you a few things you could do with the library in this piece. But you can go the extra mile by building advanced commandline applications. Thanks for reading!!!! and do let me know in the comment section how you have benefitted from this piece.&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Top 11 Advanced Tkinter Projects You Should Try This Year</title>
      <dc:creator>Khumbo Klein Chilamwa</dc:creator>
      <pubDate>Mon, 20 Feb 2023 11:54:49 +0000</pubDate>
      <link>https://dev.to/khumbolamulungu/top-11-advanced-tkinter-projects-you-should-try-this-year-115l</link>
      <guid>https://dev.to/khumbolamulungu/top-11-advanced-tkinter-projects-you-should-try-this-year-115l</guid>
      <description>&lt;p&gt;Programming is cool and more rewarding at the same time when you have what clients are looking for. These days it is not all about talking alone but rather acting on the ground, that’s why clients are opting for developers with hands-on experience. So the best way to catch a client’s attention is to work on some cool projects using a particular tool and include those projects on your resume. Know this, there will never be the best way of convincing clients than having some advanced projects that you can show off on your resume. When I first started using &lt;strong&gt;Tkinter&lt;/strong&gt; I was just creating some basic GUIs, like displaying text when a button is clicked, something that would not catch a client’s attention right? So I had to change the gears If I was ever to impress a client, so I found projects and started working on them one at a time. I have to admit that I did not finish all these projects in a single year but yeah I finished them. In this article, I will be sharing the 11 advanced &lt;strong&gt;Tkinter&lt;/strong&gt; projects that I have successfully worked on in the past years, with these projects I strongly believe that you will master the framework and be able to build your own GUI applications that you can show on your resume.&lt;/p&gt;

&lt;p&gt;Something worth mentioning here, I have just listed the projects randomly, the order in which they are listed does not in any way mean the project’s relevance and difficulty.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Age Calculator
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fadrpdtw3sospmqh4xueq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fadrpdtw3sospmqh4xueq.png" alt=" " width="624" height="298"&gt;&lt;/a&gt;&lt;br&gt;
The &lt;strong&gt;Age Calculator&lt;/strong&gt; is simply an app that calculates your age, it takes your date of birth(day, month, year) as input and calculates your age. To build this app I used the &lt;strong&gt;&lt;a href="https://ttkbootstrap.readthedocs.io/en/latest/gettingstarted/installation/" rel="noopener noreferrer"&gt;ttkbootstrap&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;datetime&lt;/strong&gt; libraries. The &lt;strong&gt;&lt;a href="https://ttkbootstrap.readthedocs.io/en/latest/gettingstarted/installation/" rel="noopener noreferrer"&gt;ttkbootstrap&lt;/a&gt;&lt;/strong&gt; library helps you style your widgets in an advanced way using bootstrap styles and the &lt;strong&gt;datetime&lt;/strong&gt; library is for working with dates.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Real-Time Currency Converter
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oc1ol9e4c7x9s00vo6z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8oc1ol9e4c7x9s00vo6z.png" alt=" " width="624" height="327"&gt;&lt;/a&gt;&lt;br&gt;
A &lt;strong&gt;Real-Time Currency Converter&lt;/strong&gt; is an app that converts currencies from a source rate to a destination rate. To successfully build this app you will need any free currency converter API(Fixer API, Exchange Rate API, Yahoo Finance API, etc), the &lt;strong&gt;tkinter&lt;/strong&gt;, &lt;strong&gt;requests&lt;/strong&gt;, and &lt;strong&gt;json&lt;/strong&gt; libraries. The &lt;strong&gt;requests&lt;/strong&gt; library is for sending a response to the API and the &lt;strong&gt;json&lt;/strong&gt; library is for converting the response to JSON data.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Gender Predictor
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwsrfk33miblth4iww77.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwsrfk33miblth4iww77.png" alt=" " width="429" height="382"&gt;&lt;/a&gt;&lt;br&gt;
The Gender Predictor app simply predicts the gender of a given name, it uses the genderize API and these 3 libraries &lt;strong&gt;tkinter&lt;/strong&gt;, &lt;strong&gt;requests&lt;/strong&gt;, and &lt;strong&gt;json&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Audio Dictionary
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59apgcxfrj4y2e5f6mor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59apgcxfrj4y2e5f6mor.png" alt=" " width="624" height="499"&gt;&lt;/a&gt;&lt;br&gt;
If you have ever fancied the idea to build a dictionary app with an audio feature, then this one is for you. With this project, you will use the &lt;strong&gt;PyDictionary&lt;/strong&gt; library for finding the words meaning and the &lt;strong&gt;pyttsx3&lt;/strong&gt; library for converting text to speech. How this app works, the user will enter a word and search for its meaning then pronounce the found word.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Real-Time Spelling Checker
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fit1ooc9tqautrm8brtek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fit1ooc9tqautrm8brtek.png" alt=" " width="624" height="466"&gt;&lt;/a&gt;&lt;br&gt;
Don’t you want to build a &lt;strong&gt;real-time spelling checker&lt;/strong&gt;, whereas you are typing your sentences in the scrollable text field the app will check in real-time for spelling errors. If this sounds cool, then this project is worth your attention this year. The libraries that you will need for this project are the &lt;strong&gt;tkinter&lt;/strong&gt;, &lt;strong&gt;re&lt;/strong&gt;, and &lt;strong&gt;nltk&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. QR Code Generator and Detector
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg7hpln6rk4ove0e3tqxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg7hpln6rk4ove0e3tqxn.png" alt=" " width="624" height="518"&gt;&lt;/a&gt;&lt;br&gt;
We all know that QR code technology is booming and that it is being incorporated with a lot of technologies like WIFIs, online payment systems, etc. Building your app that generates and detects QR codes would be a feat on its own. For this project, you will need these libraries, &lt;strong&gt;tkinter&lt;/strong&gt;, &lt;strong&gt;cv2&lt;/strong&gt; for detecting QR codes, and &lt;strong&gt;qrcode&lt;/strong&gt; for generating QR codes.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Voice Recorder
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6fwv3cc1lihjwm9mzjx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk6fwv3cc1lihjwm9mzjx.png" alt=" " width="621" height="512"&gt;&lt;/a&gt;&lt;br&gt;
Another cool project to prove your skill is a &lt;strong&gt;Voice Recorder&lt;/strong&gt;, this app records your voice for a specified amount of seconds, and after successfully recording the voice it is saved to a file for later use. The libraries required for this project are the &lt;strong&gt;sounddevice&lt;/strong&gt;, &lt;strong&gt;scipy.io.wavfile&lt;/strong&gt;, &lt;strong&gt;threading&lt;/strong&gt;, &lt;strong&gt;datetime&lt;/strong&gt;, &lt;strong&gt;time&lt;/strong&gt;, and &lt;strong&gt;os&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. PDF Viewer
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fazybdne6s850ka8830yb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fazybdne6s850ka8830yb.png" alt=" " width="624" height="515"&gt;&lt;/a&gt;&lt;br&gt;
Ever wondered how apps like Foxit reader or adobe reader work, in this project you will build your own PDF file viewer, and through this project, you will learn things like extracting data from a PDF document. The libraries you will need for this project are the &lt;strong&gt;fitz&lt;/strong&gt; from &lt;strong&gt;PyMuPDF&lt;/strong&gt;, &lt;strong&gt;tkinter&lt;/strong&gt;, and &lt;strong&gt;os&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Language Translator
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxr1ossemp64qh50zanm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgxr1ossemp64qh50zanm.png" alt=" " width="624" height="432"&gt;&lt;/a&gt;&lt;br&gt;
If you want to build your own language translator then try this project, by building this project you will learn a lot of programming concepts. You will get to design the snazzy GUI, and implement all the advanced features like voice, copy to clipboard, notifications, etc. The libraries used in this project are the &lt;strong&gt;ttkbootstrap&lt;/strong&gt;, &lt;strong&gt;googletrans&lt;/strong&gt;, &lt;strong&gt;pyttsx3&lt;/strong&gt;, and &lt;strong&gt;pyperclip&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. MP3 YouTube Downloader
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zh6wjin8ptykiupdudn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9zh6wjin8ptykiupdudn.png" alt=" " width="624" height="471"&gt;&lt;/a&gt;&lt;br&gt;
MP3 downloader is an app that downloads for you MP3 files from YouTube videos and the required libraries for this project are &lt;strong&gt;tkinter&lt;/strong&gt;, &lt;strong&gt;pytube&lt;/strong&gt;, &lt;strong&gt;threading&lt;/strong&gt;, and &lt;strong&gt;os&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. YouTube Video Downloader
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2abuou1uqiwoz1lraile.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2abuou1uqiwoz1lraile.png" alt=" " width="596" height="525"&gt;&lt;/a&gt;&lt;br&gt;
Building your video downloader like IDM would be worth it, and it’s a project that every developer would be proud of. In this project you get to build a YouTube video downloader, you will get to implement features like search resolution, display download progress on the progress bar, etc. The libraries needed are the &lt;strong&gt;tkinter&lt;/strong&gt;, &lt;strong&gt;pytube&lt;/strong&gt;, and &lt;strong&gt;threading&lt;/strong&gt;.&lt;/p&gt;

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

&lt;p&gt;I have only listed a few projects that I think will be of great use when it comes to mastering the Tkinter GUI framework, there are lots of cool projects that other developers have done, please check them out as well. A reminder, these are projects that I have worked on as an individual, and am not claiming they are the best, I only wrote this article to share what I have built using Tkinter. Thanks for reading!! &lt;/p&gt;

</description>
      <category>tkinter</category>
      <category>guiprogramming</category>
      <category>python</category>
    </item>
    <item>
      <title>How to Build a YouTube Video Search Voice Assistant</title>
      <dc:creator>Khumbo Klein Chilamwa</dc:creator>
      <pubDate>Sat, 18 Feb 2023 15:16:08 +0000</pubDate>
      <link>https://dev.to/khumbolamulungu/how-to-build-a-youtube-video-search-voice-assistant-4i9k</link>
      <guid>https://dev.to/khumbolamulungu/how-to-build-a-youtube-video-search-voice-assistant-4i9k</guid>
      <description>&lt;p&gt;Voice assistants are software programs that can understand and respond to voice commands. With the release of Amazon’s Echo and Google Home, voice assistants are becoming more popular than ever. Searching for a video on YouTube can be a hassle, especially if you don’t know what you’re looking for. But what if you could have a voice assistant that could search through YouTube videos for you? That would be pretty cool, right?  In this article, I will show you how to build a YouTube video search voice assistant using &lt;strong&gt;SpeechRecognition&lt;/strong&gt; and the &lt;strong&gt;pyttsx3&lt;/strong&gt; Python packages. So if you’re ready to get started, let’s dive right in!&lt;/p&gt;

&lt;p&gt;Here is the Table of Contents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating a Virtual Environment&lt;/li&gt;
&lt;li&gt;Installing the Required Packages&lt;/li&gt;
&lt;li&gt;Building the YouTube Video Voice Assistant

&lt;ul&gt;
&lt;li&gt;Creating the &lt;strong&gt;speak()&lt;/strong&gt; Function&lt;/li&gt;
&lt;li&gt;Creating the &lt;strong&gt;voice_assistant()&lt;/strong&gt; Function&lt;/li&gt;
&lt;li&gt;Creating the &lt;strong&gt;search()&lt;/strong&gt; Function&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Testing the YouTube Video Search Voice Assistant&lt;/li&gt;

&lt;li&gt;Conclusion &lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating a Virtual Environment
&lt;/h2&gt;

&lt;p&gt;First things first, let us create the virtual environment for the project, in your terminal run this command:&lt;br&gt;
&lt;code&gt;$ python -m venv project&lt;/code&gt;&lt;br&gt;
You can call your virtual environment any name, but just make sure the name is meaningful, not cryptic.&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing the Required Packages
&lt;/h2&gt;

&lt;p&gt;Now that the virtual environment is taken care of, it is time we install all the required packages for this project, so activate the virtual environment by running this command on Windows:&lt;br&gt;
&lt;code&gt;$ .\project\Scripts\activate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And on Linux or macOS use:&lt;br&gt;
&lt;code&gt;$ source project/bin/activate&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Having activated the virtual environment, we are ready to install the packages, run this command:&lt;br&gt;
&lt;code&gt;$ pip install pyttsx3 SpeechRecognition pyaudio&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Installing packages inside a virtual environment means that they are not global, but rather local for that one special project they are installed for. And these virtual environments come in handy because they help in managing packages very easily.&lt;/p&gt;
&lt;h2&gt;
  
  
  Building the Voice Assistant
&lt;/h2&gt;

&lt;p&gt;In this section we will build the actual YouTube Video Search Voice Assistant, we will build it from the ground up, so roll up your sleeves for we are about to go coding. &lt;/p&gt;

&lt;p&gt;The first task that we have to do is to create a new Python file, let us call it &lt;strong&gt;video_search_assistant.py&lt;/strong&gt;, as usual just be extra careful when naming your Python files, make sure the names are meaningful and that they do not conflict with the packages being used in your project. Open the file and do the following imports:&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;# this package is a web browser controller
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;webbrowser&lt;/span&gt;
&lt;span class="c1"&gt;# this package is for speach recognition
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;speech_recognition&lt;/span&gt;
&lt;span class="c1"&gt;# this package converts text to speech
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pyttsx3&lt;/span&gt;
&lt;span class="c1"&gt;# this package will be used to get the PC username
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us break down the above code, our first import is the &lt;strong&gt;webbrowser&lt;/strong&gt; package, this package is the web browser controller, and we will use it for launching the web browser. The &lt;strong&gt;speech_recognition&lt;/strong&gt; package is simply for recognizing speech, it works hand in hand with the &lt;strong&gt;pyaudio&lt;/strong&gt; package to capture voice from the microphone and process it accordingly.&lt;/p&gt;

&lt;p&gt;The other package that we are importing is the &lt;strong&gt;pyttsx3&lt;/strong&gt;, this package will convert a given text to speech and the final package being imported is the &lt;strong&gt;os&lt;/strong&gt; package, which we will use for getting the computer’s username.&lt;/p&gt;

&lt;p&gt;After taking care of the imports, our next task will be creating the &lt;code&gt;speak()&lt;/code&gt; function, this function will help turn text data into audio data, now just below the imports paste the following 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="c1"&gt;# function to turn textual data into audio data
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# initializing the pyttsx3 object
&lt;/span&gt;    &lt;span class="n"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pyttsx3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="c1"&gt;# gets the speaking rate
&lt;/span&gt;    &lt;span class="n"&gt;rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rate&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# setting the speaking rate
&lt;/span&gt;    &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;rate&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;125&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# getting the available voices
&lt;/span&gt;    &lt;span class="n"&gt;voices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;voices&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# setting the second voice, the female voice
&lt;/span&gt;    &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;voice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;voices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# this function takes the word to be spoken
&lt;/span&gt;    &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;say&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;command&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# this function processes the voice commands
&lt;/span&gt;    &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;runAndWait&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 code above, we are creating a function &lt;code&gt;speak()&lt;/code&gt; that is taking &lt;strong&gt;command&lt;/strong&gt; as an argument, inside this function we are initializing the &lt;strong&gt;pyttsx3&lt;/strong&gt; object, then using this object we are getting and setting the speaking rate. We are also able to get a voice from the available voices and set it, in our case we are using the second voice which happens to be the female voice.&lt;/p&gt;

&lt;p&gt;After this, we are passing the command to the &lt;code&gt;say()&lt;/code&gt; function, and the &lt;code&gt;runAndWait()&lt;/code&gt; function processes the voice commands. &lt;/p&gt;

&lt;p&gt;Our next task is to create the &lt;code&gt;voice_assistant()&lt;/code&gt; function, so in the file just below the &lt;code&gt;speak()&lt;/code&gt; function paste the following 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="c1"&gt;# creating a Recognizer object
&lt;/span&gt;&lt;span class="n"&gt;recognizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;speech_recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Recognizer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# prints the message to let the user know to start speaking
&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;Say something, am listening&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# the function for recognizing speech and processing it accordingly
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;voice_assistant&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# the try statement will execute the speech recognizing code
&lt;/span&gt;    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# here we are creating a context for the speech_recognition.Microphone() function
&lt;/span&gt;        &lt;span class="c1"&gt;# this enables us to use the microphone
&lt;/span&gt;        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;speech_recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Microphone&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;mic&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="c1"&gt;# this listens to the ambient noise for the specified duration
&lt;/span&gt;            &lt;span class="n"&gt;recognizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;adjust_for_ambient_noise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;duration&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="c1"&gt;# capturing speech from the default microphone
&lt;/span&gt;            &lt;span class="n"&gt;audio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;recognizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="c1"&gt;# recognizing speech using google speech recognition API 
&lt;/span&gt;            &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;recognizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;recognize_google&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="c1"&gt;# this converts the text to lowercase text
&lt;/span&gt;            &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="c1"&gt;# calling the speak function, it takes text as an argument
&lt;/span&gt;            &lt;span class="nf"&gt;speak&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;Be patient while i search for you all &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; videos&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="c1"&gt;# this will print the captured word
&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;Searching &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;text&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;span class="c1"&gt;# this except statement catches an error when the assistant fails to recognize the said word   
&lt;/span&gt;    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;speech_recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UnknownValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# calling the speak function, it takes text as an argument
&lt;/span&gt;        &lt;span class="nf"&gt;speak&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;Sorry i did not hear you!!!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&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;Sorry i did not hear you!!!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# this except statement catches an error when the assistant fails to recognize the said word 
&lt;/span&gt;    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;speech_recognition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RequestError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# calling the speak function, it takes text as an argument
&lt;/span&gt;        &lt;span class="nf"&gt;speak&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;Make sure you have a stable internet connection!!!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&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;Make sure you have a stable internet connection!!!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# this is a function call 
&lt;/span&gt;&lt;span class="nf"&gt;voice_assistant&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we move any further, let us break this code down so that we are on the same page. We are creating a speech recognition object via &lt;code&gt;speech_recognition.Recognizer()&lt;/code&gt; function, below it we have a &lt;code&gt;print()&lt;/code&gt; function. Then we are creating a function called &lt;code&gt;voice_assistant()&lt;/code&gt;, inside this function we have a &lt;code&gt;try/except&lt;/code&gt;block, the first &lt;code&gt;except&lt;/code&gt; statement catches &lt;code&gt;UnknownValueError&lt;/code&gt; which occurs when the voice assistant fails to recognize the speech and the second &lt;code&gt;except&lt;/code&gt; statement catches a &lt;code&gt;RequestError&lt;/code&gt; caused by unstable or no internet connection.&lt;/p&gt;

&lt;p&gt;If you notice, inside these two &lt;code&gt;except&lt;/code&gt; statements we are calling the &lt;code&gt;speak()&lt;/code&gt; function and we are passing a &lt;strong&gt;string&lt;/strong&gt; as an argument and we are also printing the same &lt;strong&gt;string&lt;/strong&gt; via the &lt;code&gt;print()&lt;/code&gt; function. Having the &lt;code&gt;speak()&lt;/code&gt; function and the print statement inside the two &lt;code&gt;except&lt;/code&gt; statements at once seems repetitive, but this is for testing purposes only.&lt;/p&gt;

&lt;p&gt;Inside the try statement, we are declaring the microphone as the source of input and this code:&lt;br&gt;
&lt;code&gt;recognizer.adjust_for_ambient_noise(mic, duration=0.5)&lt;/code&gt;&lt;br&gt;
helps let the recognizer waits for a duration of &lt;strong&gt;0.5&lt;/strong&gt; seconds to adjust the energy threshold based on the surrounding noise levels. According to &lt;strong&gt;SpeechRecognition&lt;/strong&gt; documentation, the best duration for accurate results is &lt;strong&gt;0.5&lt;/strong&gt; seconds.&lt;/p&gt;

&lt;p&gt;After adjusting the ambient noise, we are letting the **recognizer **capture audio from the microphone using the code:&lt;br&gt;
&lt;code&gt;audio = recognizer.listen(mic)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This audio data is then converted to text using this line of code:&lt;br&gt;
&lt;code&gt;text = recognizer.recognize_google(audio)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Finally, we are calling the &lt;code&gt;speak()&lt;/code&gt; function as well and we are passing the argument text and we are printing the text.&lt;/p&gt;

&lt;p&gt;We will now test the program, make sure your computer’s microphone is working and that your environment is quiet. Such an environment is helpful because it will enable the voice assistant to recognize the speech without any problems, but if the environment is the noise the voice assistant will have difficulties distinguishing the speech from noise.&lt;/p&gt;

&lt;p&gt;In your terminal run this command:&lt;br&gt;
&lt;code&gt;$ python video_search_assistant.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Say a word when you are prompted to, the first output will be an audible voice and the second will be this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Say something, am listening
Searching programming
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It seems the program can capture the speech and process it accordingly.&lt;/p&gt;

&lt;p&gt;We will now move on to creating the &lt;code&gt;search()&lt;/code&gt; function, this function will enable the voice assistant to search for YouTube videos, so above the &lt;code&gt;speak()&lt;/code&gt; function or just below the imports, paste this 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="c1"&gt;# function for searching youtube videos
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# creating the search url
&lt;/span&gt;    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&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;https://www.youtube.com/results?search_query=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
    &lt;span class="c1"&gt;# opening the webbrowser
&lt;/span&gt;    &lt;span class="n"&gt;webbrowser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are creating a function that takes &lt;strong&gt;query&lt;/strong&gt; as an argument, the function is called &lt;code&gt;search()&lt;/code&gt;, then we are creating a &lt;strong&gt;URL&lt;/strong&gt;, this is just a youtube video search &lt;strong&gt;URL&lt;/strong&gt;. After everything, the &lt;code&gt;webbrowser.get().open(url)&lt;/code&gt; will open the &lt;strong&gt;URL&lt;/strong&gt; in the web browser. Remember, we will not type the &lt;strong&gt;URL&lt;/strong&gt; manually but we will get it from the microphone.&lt;/p&gt;

&lt;p&gt;Now to do a YouTube video search we need to call the &lt;code&gt;search()&lt;/code&gt; function, we will call it in the try statement of the &lt;code&gt;voice_assistant()&lt;/code&gt; function since we want it to search the data captured from the microphone. Below this line of code:&lt;br&gt;
&lt;code&gt;text = str(text.lower())&lt;/code&gt;&lt;br&gt;
Paste this line of code:&lt;br&gt;
&lt;code&gt;search(text)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And below the &lt;code&gt;voice_assistant()&lt;/code&gt; function, add this 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="c1"&gt;# this gets the username of the computer 
&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getlogin&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;# calling the speak function to welcome the user by the username
&lt;/span&gt;&lt;span class="nf"&gt;speak&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;Welcome &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;username&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;span class="c1"&gt;# asking the user what to search for
&lt;/span&gt;&lt;span class="nf"&gt;speak&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;What do you want to search for?&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;h2&gt;
  
  
  Testing the YouTube Video Search Voice Assistant
&lt;/h2&gt;

&lt;p&gt;In this section, we will test the program, and let us search for programming videos. You can run it again using:&lt;br&gt;
&lt;code&gt;$ python video_search_assistant.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the program runs successfully, it will welcome you and ask you what videos you want to search for, and if you provide valid input you will get this out:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxemmszfdy9p6xpppzn0w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxemmszfdy9p6xpppzn0w.png" alt=" " width="624" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And in the terminal you will get this output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Say something, am listening
Searching programming
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the program and speak a cryptic word, the program will give you this output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Say something, am listening
Sorry i did not hear you!!!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And at the same time, the &lt;code&gt;speak()&lt;/code&gt; function will echo the same message.&lt;/p&gt;

&lt;p&gt;And if you have an unstable or no internet connection, the output will be as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Say something, am listening
Make sure you have a stable internet connection!!!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This message will again be echoed by the &lt;code&gt;speak()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Congratulations on creating your voice assistant, and to make the code a little cleaner you can remove all the &lt;strong&gt;print&lt;/strong&gt; statements. If you observe well there are four print statements. &lt;/p&gt;

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

&lt;p&gt;This article has shown you how to build a YouTube Video Search Voice Assistant. I hope there is so much that you have learned and that you can use this knowledge to create your own amazing projects. If you want to further this project feel free to do so, you can add as many cool features as you want. Thanks for reading.&lt;/p&gt;

</description>
      <category>automation</category>
      <category>voiceassistant</category>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Verify Email Addresses Using Python</title>
      <dc:creator>Khumbo Klein Chilamwa</dc:creator>
      <pubDate>Fri, 17 Feb 2023 19:59:25 +0000</pubDate>
      <link>https://dev.to/khumbolamulungu/how-to-verify-email-addresses-using-python-3aae</link>
      <guid>https://dev.to/khumbolamulungu/how-to-verify-email-addresses-using-python-3aae</guid>
      <description>&lt;p&gt;Email verification is a process that involves the confirmation of the authenticity or legitimacy of an email address. Nowadays businesses are integrating email verification into their day-to-day operations and this has proved to be more effective as it helps them keep only customers' email addresses that are valid and reachable. The email verifying tools that are available out there are cool and sophisticated but they come with a price tag, for a developer that should never be a huddle because you can build your own tool to verify a single email or bulk email. In this article, I will show you how you can build your own email verification tool using the Python library called &lt;a href="https://pypi.org/project/verify-email/" rel="noopener noreferrer"&gt;verify-email&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is the Table of Contents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Installing the Required Package&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verifying a Single Email Address&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verifying Bulk Email Addresses&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Final Thoughts&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installing the Required Package
&lt;/h2&gt;

&lt;p&gt;First things first, you need to have the verify-email package installed. Ensure that &lt;strong&gt;pip&lt;/strong&gt; is working on your computer, in your terminal run the below command to install the package:&lt;br&gt;
&lt;code&gt;$ pip install verify-email&lt;/code&gt;&lt;br&gt;
The &lt;strong&gt;&lt;a href="https://pypi.org/project/verify-email/" rel="noopener noreferrer"&gt;verify-email&lt;/a&gt;&lt;/strong&gt; package verifies email addresses by checking the domain name and pinging the handler or username for its existence.&lt;/p&gt;
&lt;h2&gt;
  
  
  Verifying a Single Email Address
&lt;/h2&gt;

&lt;p&gt;Firstly, open a new Python file, call it &lt;strong&gt;email-verifier-script.py&lt;/strong&gt;, and on top of the file do the following import:&lt;br&gt;
&lt;code&gt;from verify_email import verify_email&lt;/code&gt;&lt;br&gt;
After doing the import, you need to create an email verifying handler, this is a function that will handle the email verification process. Call the function &lt;code&gt;email_verifier()&lt;/code&gt; and make it look like 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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;email_verifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# verifying email using verify_email function
&lt;/span&gt;    &lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;verify_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# checking if the verify value is True
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&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="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is a valid email address&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="c1"&gt;# checking if the verify value is False
&lt;/span&gt;    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;:&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="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is not a valid email address&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;The &lt;code&gt;email_verifier()&lt;/code&gt; function is taking an argument email, this will be provided by the user, so do the following:&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;# getting email from user
&lt;/span&gt;&lt;span class="n"&gt;my_email&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 email address:&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;After the user has provided the email address, it needs to be verified, to do that do a function call as below:&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;# calling the email_verifier function
&lt;/span&gt;&lt;span class="nf"&gt;email_verifier&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;my_email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you are set to verify your first email address, open the terminal and navigate to the directory where the script is located. Run this script using this command:&lt;br&gt;
&lt;code&gt;python email-verifier-script.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will be prompted to enter an email address, if the email address is valid, the output will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmr2x4mognpwonyby8uzf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmr2x4mognpwonyby8uzf.png" alt=" " width="624" height="47"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enter an invalid email address, this is what you get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqz84jsstj8nsmsevg8k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbqz84jsstj8nsmsevg8k.png" alt=" " width="599" height="47"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Verifying Bulk Email Addresses
&lt;/h2&gt;

&lt;p&gt;In this section, you will get to verify a list of email addresses, so tweak the &lt;strong&gt;email-verifier-script.py&lt;/strong&gt; file so that it looks like 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="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;verify_email&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;verify_email&lt;/span&gt;

&lt;span class="c1"&gt;# a list of email addresses to be verified
&lt;/span&gt;&lt;span class="n"&gt;email_addresses&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;khumboklein@gmail.com&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;muo@gmail.com&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                   &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;admin@gmail.com&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;kchilamwa@hackbits.tech&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                   &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;trainings@updates.internshala.com&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;noreply@medium.com&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                   &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;maryellen.m@valnetinc.com&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;email_addresses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# verify individual email address
&lt;/span&gt;    &lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;verify_email&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# checking if verify is True
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&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="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is a valid email address&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# checking if verify is False
&lt;/span&gt;    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;:&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="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is not a valid email address&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 the code snippet, there is a list of email addresses. The for loop is looping through all the email addresses in the list.  Inside the &lt;code&gt;for loop&lt;/code&gt;, an email is being verified individually.&lt;/p&gt;

&lt;p&gt;Running the script, the output will be:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faqhw1avtqr31hb41r74o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faqhw1avtqr31hb41r74o.png" alt=" " width="624" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;With Python’s versatility, you can build your free email address verifier with a few lines of code, this comes in handy and it’s cheaper than using a premium email verifying service.&lt;/p&gt;

</description>
      <category>api</category>
    </item>
    <item>
      <title>Getting to know the .NET framework</title>
      <dc:creator>Khumbo Klein Chilamwa</dc:creator>
      <pubDate>Fri, 29 Apr 2022 11:30:22 +0000</pubDate>
      <link>https://dev.to/khumbolamulungu/getting-to-know-the-net-framework-9gm</link>
      <guid>https://dev.to/khumbolamulungu/getting-to-know-the-net-framework-9gm</guid>
      <description>&lt;p&gt;In this article, you will get to know the .NET framework, why it is an investment-worthy of your time, and what you can build using this technology. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is the .NET framework?
&lt;/h2&gt;

&lt;p&gt;Before we dive deeper into this article, let us get to understand what a framework is. A framework is a collection of already written code that helps the programmer solve some complex tasks that are part of the software development process. For example, writing code to authenticate users is more tedious and time-consuming, so time being one of the crucial factors in the software development business, developers came up with a solution to this by introducing frameworks that come with all necessary features out of the box.&lt;br&gt;
According to Microsoft, the founder and creator of the framework, .NET also pronounced as dot net is said to be a software development framework for building and running applications on windows. The framework is C# based meaning it was built using the C# programming language, and my advice to those willing to learn this popular framework would be, to learn some C# basics, this will help you to get familiar with the syntax the framework uses, since it is C# like.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the .NET framework?
&lt;/h2&gt;

&lt;p&gt;Probably by now, you might be asking yourself questions like why should I learn this framework for my career development and is it really worth my time, and who is still using it out there, maybe I might be just one of those geeks using obsolete technology.  All these questions are understandable and they all make sense; it has been the norm for everyone new to any technology to ask lots of these kinds of questions. So why should you learn the .NET framework? Listed below are some of the reasons why you should learn this popular framework as an addition to your stack.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It offers better in-built user interface(UI) controls and supports other UI controls such as Telerik which is drag and drop.&lt;/li&gt;
&lt;li&gt;it takes security seriously, for example, it offers cryptography for securing data, and its environment is highly secure.&lt;/li&gt;
&lt;li&gt;It can be easily integrated with other Microsoft applications e.g. MS office applications, and emails.&lt;/li&gt;
&lt;li&gt;It uses the MVC (Model View Controller) architecture just like the other popular web development frameworks e.g. Django, Laravel, and Ruby on rails.&lt;/li&gt;
&lt;li&gt;It helps you to quickly deploy your applications&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Listed above are just some of the reasons you should learn the .NET framework, I have not exhausted everything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Still doubting the .NET framework?
&lt;/h2&gt;

&lt;p&gt;Just like the other popular frameworks available, the .NET framework has been around for some time and because it is mature and feature-rich, famous and big companies are embracing it as their primary framework for building their business solutions. Listed below are some of the companies that use the .NET framework.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Microsoft (founder and creator)&lt;/li&gt;
&lt;li&gt;Dell&lt;/li&gt;
&lt;li&gt;Stack Overflow&lt;/li&gt;
&lt;li&gt;Accenture&lt;/li&gt;
&lt;li&gt;Trustpilot&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What you can build using the .NET framework
&lt;/h2&gt;

&lt;p&gt;.NET being a versatile framework, a lot of businesses are relying on it when it comes to building their quality and reliable business solutions. Businesses that have embraced this technology are now using it for building.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Web-based applications&lt;/li&gt;
&lt;li&gt;Web services&lt;/li&gt;
&lt;li&gt;Form-based applications&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;In this article, you have learned what a .NET framework is, why you should learn it and what you can build after adding it to your stack.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>opensource</category>
      <category>career</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
