<?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>Forem: Emmanuel Tanimowo</title>
    <description>The latest articles on Forem by Emmanuel Tanimowo (@mannuel25).</description>
    <link>https://forem.com/mannuel25</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%2F534016%2Fa9f9cac9-4e77-4e08-8ea6-052024c3850b.png</url>
      <title>Forem: Emmanuel Tanimowo</title>
      <link>https://forem.com/mannuel25</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mannuel25"/>
    <language>en</language>
    <item>
      <title>Handling Exceptions In Python</title>
      <dc:creator>Emmanuel Tanimowo</dc:creator>
      <pubDate>Sun, 05 Dec 2021 21:28:51 +0000</pubDate>
      <link>https://forem.com/mannuel25/handling-exceptions-in-python-2d0f</link>
      <guid>https://forem.com/mannuel25/handling-exceptions-in-python-2d0f</guid>
      <description>&lt;p&gt;Things rarely go as planned, especially in the world of programming. Errors are unavoidable when writing code, which can be frustrating at times. &lt;/p&gt;


&lt;p&gt;&lt;a href="https://giphy.com/gifs/frustrated-ryan-gosling-wMvESGxZ0Cqd2"&gt;via GIPHY&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article, I'll show you how to handle exceptions in Python.&lt;/p&gt;



&lt;h3&gt;
  
  
  What is an Exception?
&lt;/h3&gt;

&lt;p&gt;An exception is an error that occurs while the program is running. In some cases, an exception may cause the program to stop or produce unexpected results. For example, taking a look at Fig 1.0. This program gets two numbers from the user and divides the first number by the second number, and displays the result. However, when the program is run, an exception occurs as shown in Fig 1.1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2OxjITAJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637251911162/ljPlx3RtS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2OxjITAJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637251911162/ljPlx3RtS.png" alt="carbon (10).png" width="880" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.0&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UvsSyKlI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637311138943/V-Z41wY8F.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UvsSyKlI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637311138943/V-Z41wY8F.png" alt="carbon (11).png" width="880" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.1&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;The error message displayed in Fig 1.1 is called a &lt;strong&gt;&lt;em&gt;traceback&lt;/em&gt;&lt;/strong&gt;. A traceback provides information about the line number(s) that resulted in the exception. In Fig. 1.1, the last line of the error message shows the name of the exception that was raised (ZeroDivisionError) and a brief description of the error that caused the exception to be raised (integer division or module by zero).&lt;br&gt;
&lt;/p&gt;

&lt;br&gt;
We can improve the error-resistance of this program by enclosing it in a try-except-else block. When the program is run, if no exceptions are raised, the statements in the else block are executed after the statements in the try block. But if an exception is raised, the statements in the else block are skipped. The following is the general structure of a try-except-else block.

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--myf787d1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637312685830/TqzRzhqpK.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--myf787d1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637312685830/TqzRzhqpK.png" alt="carbon (13).png" width="654" height="818"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's put the try-except-else block to work on the program now. As shown in Fig 1.2, we ask Python to try to complete the division operation in a try block, which includes only the code that could cause an error. Any code that is dependent on the try block's success is added to the else block. In this example, if the division operation is successful, the result is displayed using the else block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FZ70aYSZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637315054681/tNoW6oxuN.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FZ70aYSZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637315054681/tNoW6oxuN.png" alt="carbon (14).png" width="880" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.2&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;The except block also tells Python how to handle a ZeroDivisionError. A message is displayed if the try block fails due to a division by zero error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GadKhD4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637317733468/mO9GWoDKO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GadKhD4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637317733468/mO9GWoDKO.png" alt="carbon (15).png" width="824" height="744"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling multiple exceptions in your program
&lt;/h3&gt;

&lt;p&gt;The code in a try block can often throw multiple types of exceptions. You must write an except block for each type of exception you want to handle in such instances. Here's a &lt;a href="https://www.tutorialsteacher.com/python/error-types-in-python"&gt;link&lt;/a&gt; to a resource that explains in detail the different types of exceptions that could occur in your program. &lt;/p&gt;

&lt;p&gt;A ZeroDivisionError may occur if we attempt to divide a number by zero. In addition, if incorrect input is entered, such as &lt;em&gt;twelve&lt;/em&gt;, which has a string data type, a ValueError may occur, and an exception is raised when Python tries to convert a string to an integer as shown in Fig 1.3. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wSY7zWgS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637320800936/9aI7hgo5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wSY7zWgS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637320800936/9aI7hgo5l.png" alt="carbon (17).png" width="880" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.3&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Fig 1.4 shows us how we can handle the two exceptions. If an exception occurs in the try block, Python examines each of the except blocks in the try-except block from top to bottom. It branches to an except block that specifies a type that matches the type of exception that occurred when it finds one. Python displays the result if none of the except blocks specify a type that matches the exception.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hNT30ZwX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318180781/W8SyzoJQq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hNT30ZwX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637318180781/W8SyzoJQq.png" alt="carbon (16).png" width="880" height="608"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.4&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;



&lt;h3&gt;
  
  
  Using one except block to handle all exceptions
&lt;/h3&gt;

&lt;p&gt;The previous example showed us how we could handle two types of exceptions individually in a try-except block. Sometimes you might want to write a try-except block that simply handles any exception raised in a try block and responds the same way regardless of the exception's type. In a try-except block, you can accomplish this by writing one except block that does not specify a particular type of exception as shown in Fig 1.5. If any exception is raised, a friendly message is displayed to you.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DQsZ9Wui--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637323598463/88QZphgMFu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DQsZ9Wui--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637323598463/88QZphgMFu.png" alt="carbon (19).png" width="880" height="698"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.5&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;



&lt;h3&gt;
  
  
  Displaying an exception's default error message
&lt;/h3&gt;

&lt;p&gt;When an exception is raised, an object known as &lt;strong&gt;&lt;em&gt;exception object&lt;/em&gt;&lt;/strong&gt; is created in memory. If an exception goes unhandled, the exception object usually contains a default error message about the exception, which is the same error message that appears at the end of a traceback. You can optionally assign the exception object to a variable when writing an except block, as shown here:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;except ValueError as err&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This catches ValueError exceptions; the expression following the except block specifies that the exception object is assigned to the variable &lt;em&gt;err&lt;/em&gt;. The name &lt;em&gt;err&lt;/em&gt; isn't particularly memorable. That is simply the name we have chosen for the sake of illustration. You are free to use any name you want :). After that, you can use the print function to display the default error message by passing the err variable. Figure 1.6 shows an example of how this is accomplished.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3r7GYsne--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637327137209/RpQE2M8qR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3r7GYsne--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637327137209/RpQE2M8qR.png" alt="carbon (20).png" width="880" height="851"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.6&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;Fig 1.6 shows how to display an exception's default error message. You can also write each except block to display the default error message of any exception that should be raised.&lt;/p&gt;

&lt;p&gt;Furthermore, if you only want one except block to handle all of the exceptions raised in the try block, you can specify Exception as the type as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--COmtDlDi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637327705948/3HZfsdTxJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--COmtDlDi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637327705948/3HZfsdTxJ.png" alt="carbon (21).png" width="880" height="746"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Failing Exceptions Silently
&lt;/h3&gt;

&lt;p&gt;When an exception occurred in the preceding examples, an error message was displayed. However, you may not want to disclose every exception you encounter. When an exception occurs, you may wish the program to fail silently and proceed as if nothing happened. To have a program fail silently, construct a try block as usual, but in the except block, use the pass keyword to specifically tell Python to do nothing, as seen below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bQ0fdMYp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637331221817/8a3f3tlbL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bQ0fdMYp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637331221817/8a3f3tlbL.png" alt="carbon (23).png" width="880" height="769"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Exception handling with the Finally keyword
&lt;/h3&gt;

&lt;p&gt;Finally is a keyword in Python that is always executed after a try-except block. Even if the try block throws an exception, any code written in the finally block will always be executed. Fig 1.7 shows an example of how that is done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T_Uq7ov1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637330061076/gq72bJcJbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T_Uq7ov1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1637330061076/gq72bJcJbn.png" alt="carbon (22).png" width="880" height="909"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Fig 1.7&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;



&lt;h3&gt;
  
  
  What happens if an exception isn't handled?
&lt;/h3&gt;

&lt;p&gt;The program will terminate if an exception is not handled. There are two ways that a thrown exception can go unnoticed. The first option is for the try-except block to have no except blocks that define the appropriate exception type. The second option is for the exception to be raised from outside of a try block. In any instance, the program will come to a halt due to the exception.&lt;/p&gt;



&lt;br&gt;
This is the last section of the article. Thank you for taking the time to read through; if you found the content useful, you can subscribe to my &lt;a href="https://mannuel.hashnode.dev/"&gt;newsletter&lt;/a&gt; to be notified when new articles are published.

&lt;p&gt;I'd like to connect with you as well, so let's connect on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://twitter.com/emma_tanimowo"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linkedin.com/in/emmanuel-tanimowo-6122291aa"&gt;LinkedIn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Importing Modules In Python</title>
      <dc:creator>Emmanuel Tanimowo</dc:creator>
      <pubDate>Sun, 08 Aug 2021 16:01:32 +0000</pubDate>
      <link>https://forem.com/mannuel25/importing-modules-in-python-1503</link>
      <guid>https://forem.com/mannuel25/importing-modules-in-python-1503</guid>
      <description>&lt;h2&gt;
  
  
  What is a Module?
&lt;/h2&gt;

&lt;p&gt;A Module is a Python source code that contains functions and/or classes you want to make use of. &lt;br&gt;
For instance, the math module contains various mathematical functions. To use these functions in the math module, you must import them. An import statement tells Python to make the functions/classes in the module available in your current program file.&lt;/p&gt;
&lt;h2&gt;
  
  
  There are several ways to import a module in Python:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  - Importing an Entire Module:
&lt;/h3&gt;

&lt;p&gt;To import an entire module let's say math module, you make use of the &lt;code&gt;import&lt;/code&gt; keyword, followed by the function name. &lt;/p&gt;

&lt;p&gt;Syntax: &lt;code&gt;import function_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To import the math module; &lt;code&gt;import math&lt;/code&gt;, this statement tells the Python interpreter to load the contents of the module into memory, that is making the functions and/or classes stored in the math module available in your current program file. After importing a module, you have can make use of all the functions or classes it contains. &lt;/p&gt;

&lt;p&gt;To call each function in the module, you make use of the dot notation; the module's name followed by a dot then the name of the function.&lt;/p&gt;

&lt;p&gt;Syntax:  &lt;code&gt;module_name.function_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Let's use the sqrt function in the module as an example, when it is called the square root of the number entered is returned:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import math
n = math.sqrt(25)   # get the square root of 25
print (n)
&amp;gt;&amp;gt;&amp;gt; 5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  - Importing a specific Function or Class:
&lt;/h4&gt;

&lt;p&gt;There are times you only want to make use of a specific function or class from a module. In such a case, you use the &lt;code&gt;from&lt;/code&gt; keyword with the &lt;code&gt;import&lt;/code&gt; statement.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;from module_name import function_name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;This statement causes only the function to be imported from the module. &lt;/p&gt;

&lt;p&gt;Here's an example of how to import and use only the sqrt function from the math module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from math import sqrt
n = sqrt(25)   # get the square root of 25
print (n)
 &amp;gt;&amp;gt;&amp;gt; 5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can as well import several specific functions or classes from a module. To do that, specify the names of the functions or classes to be imported separated by commas:&lt;/p&gt;

&lt;p&gt;Syntax: &lt;code&gt;from module_name import function_a, function_b, function_c&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;An example showing how to import the sqrt function and radians function from the math module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from math import sqrt, radians
n = sqrt (25)   # get the square root of 25
c = radians (180)   # convert degree value into radians
print (n)
&amp;gt;&amp;gt;&amp;gt; 5.0
print (c)
&amp;gt;&amp;gt;&amp;gt;&amp;gt; 3.141592653589793
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  - Using the &lt;code&gt;as&lt;/code&gt; keyword to give Alias:
&lt;/h4&gt;

&lt;p&gt;If the name of the module you want to import is too long, you could give it an alias- an alternate name to use when using the module (like a nickname). When you give a module an alias, it renames the module's name using the provided alias.&lt;/p&gt;

&lt;p&gt;An example of how to import the math module using an alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import math as mth   # given math module an alias `mth`
n = mth.sqrt(25)   # get the square root of 25
print (n)
&amp;gt;&amp;gt;&amp;gt; 5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition, if the name of a function or class you want to import conflicts with an existing name in your current program file, or the name of the function or class is too long, you could also give it an alias. &lt;/p&gt;

&lt;p&gt;An example of how to import only the radians function from the math module using an alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from math import radians as rad   # given the function radians an alias `rad`
c = rad(180)
&amp;gt;&amp;gt;&amp;gt; 3.141592653589793
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  - Wildcard imports:
&lt;/h4&gt;

&lt;p&gt;You can tell python to import the entire contents of a module by making use of the asterisk operator(*). &lt;/p&gt;

&lt;p&gt;Syntax: &lt;code&gt;from math import *&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Having imported all the contents in the module into your current program file, each function can be called by its name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from math import *
n = sqrt(25)   # get the square root of 25
print (n)
&amp;gt;&amp;gt;&amp;gt; 5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nonetheless, it's best not to use this approach, because it can lead to name clashes while importing several modules. A name clash could occur- when two or more modules contain identifiers with the same name and are imported into the same file.&lt;br&gt;
To avoid name clashes, you should import the specific functions or classes you need from the module, or you import the entire module and make use of the dot notation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Thanks for taking your time to read, please feel free to drop some comments below.
&lt;/h4&gt;

</description>
      <category>python</category>
      <category>pythonbeginner</category>
      <category>pythonmodules</category>
      <category>programmingtips</category>
    </item>
  </channel>
</rss>
