Wednesday, August 26, 2015

Python Fundamentals | Importing Python Library

Introduction

        In previous post we have made our first step into the world of python.In this short post we will see how to import external libraries into python file.
The Keyword "Import"

        if you want to import external libraries into your python code is simply use "import" keyword. like in Java.

Here's a simple example of import keyword that shows how to import library call "Math" in Python code.
  • import math
 Lets just flashback to our previous post. We didn't need a semicolon or any other delimiter to end the statement. That's the one of feature of python language that distinguish python from other languages like C# or c or c++ etc.

You can also import single component from library. Following statement show how you can import single component from python library.
  • from math import sqrt
the "sqrt()" method become available to your python source file. you can also give an alias name to imported component.
  •  from math import sqrt as st
 you can then call sqrt() method as "st(args)".
 In the next post we will look at role of white space in python.