image from pixabay

This video tutorial is for the individuals who wants to Learn Python Programming Language. It is a simple Python Tutorial for Beginners.

Whenever you exit Python interpreter and enter again, the definitions you have made (e.g. functions and variables) get lost. And by writing a  program using a code editor to prepare the input for the interpreter and run it with that file as input instead. This is known as creating a script.

As your program gets longer, you may want to split it into several files for easier maintenance. Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module.

A module is a file containing Python definitions and statements. The file name is the module name with the appended. And inside a module, the module’s name (as a string) is available as the value of the global variable __name__.

Below here, we are explaining what Python script and Python Module are. We are using the example of the fibo module to perform a Fibonacci function.

The simple Python script code can be found here:

# Fibonacci numbers module 
 def fib(n): # write Fibonacci series up to n 
         a, b = 0, 1 
         while a < n: 
                 print(a, end=' ') 
                 a, b = b,  a+b 

def fib2(n): # return Fibonacci series up to n 
         result = [] 
         a, b = 0, 1 
         while a < n: 
                 a, b = b, a+b 
         return result

Now enter the below Python interpreter and import the fibo module with the following command:

import fibo

And by using the module fibo, you can access the functions that you had already created for your program using the Python script.

If you have any question or comment, do not hesitate to ask us.

Quote: The moon looks upon many night flowers; the night flowers see but one moon. – Jean Ingelow