In this tutorial we are going to learn :

  • What is a Module in Python
  • Creating a Module
  • The dir() function
  • Re – Naming a Module

 

 

What is a Module in Python

 

Let’s think of a library example. In the library, all books are not the same place. Each book type is placed in some special places in the library. So consider module as a code library.

 

 

Creating a Module

 

Step 1 )  Click the project and then “New” and then “Python File” .

 

 

Step 2 ) Let’s give a name to our Module. We gave “my_module” .

 

 

Step 3 ) Let’s write a simple function to our new module.

 

 

Step 4 ) Importing our module with the import keyword and as you can see we have access to our function in our module .

 

 

Step 5 ) Let’s run the program. And you see the result.

 

 


The dir() Function


We use the dir() function to list all function names or variable names in our module.

Example :

 

 

 

Re – Naming a Module

 

You can use the as keyword to re – name a module .

Example :

Leave a Reply

Your email address will not be published. Required fields are marked *