Python 2.2 - Python libraries/packages

 

Python libraries/packages

A Python library or a package is a third party software that is provided or contributed by some other persons or companies which will be used to develop variety of applications. Most of the libraries are not provide by Python so we have to download them explicitly. Python has a very large library of packages such as numpy, pandas, matplotlib, tkinter, math, xlrd etc. These packages are required for different purposes. Actually Python is a very short language but it has a vast library of 3rd party software. For example, if we want to create desktop applications, then we can use one of the available libraries for GUI applications. Tkinter is one of the available GUI libraries. To download these libraries, we can use ‘pip’ command. To do this, open system command prompt and use ‘pip’ command as shown below –

C:\> pip install <package name>

pip – pip (Python installation of packages) is a program that comes with Python software. It is used to download and install Python libraries or 3rd party software or packages. Remember ‘pip’ comes with Python version 3.4 or later. If you have an older version of Python, then you will have to download ‘pip’ separately. I don’t recommend downloading ‘pip’ separately on an older version of Python. If you are on older version of Python such as Python 2.4 etc., then update the Python.

1.   Numpy

numpy(numerical Python) is a package that is used to create n dimensional arrays in Python since Python supports only 1 dimensional array. If we want to create 2D or 3D arrays, then we must install numpy. To download and install this package, use following command –

C:\> pip install numpy

2.   Pandas

This library is used in data analysis. This package is mostly used by data scientists and data analysts. To download and install this package, use following command – 

C:\> pip install pandas

3.   Matplotlib

matplotlib is another important package in Python that is used to create 2D graphics. It is used to show the data in the form of graphs, charts etc. To download and install this package use following command – 

C:\> pip install matplotlib

Writing first Python program

Python programs are saved with “.py” extension (extension defines the type of a file) where py tells that it is a Python program. An extension is a word in any file name after a dot (.) symbol. For example, sample.txt, sample.docx, sample.pptx, sample.mp4, sample.mp3 etc. The words after dot (.) symbol are extensions of files (.txt, .docx, .pptx, .mp4, .mp3). So in Python, we can have ‘sample.py’ where ‘sample’ is the file name and ‘.py’ is the extension.

We have two modes or styles to write Python programs

·         Interactive mode

·         Script mode

Interactive mode – In interactive mode, as soon as we write a statement, the interpreter executes it instantly. You should use Interactive method for only practicing Python syntax. We should not write a full program in interactive mode. Python’s command line window is used for this purpose. we can also use Python’s IDLE window for interactive mode. Actually Python’s IDLE window can be used for both the interactive and script mode. How? We will see in next topic.

Script mode – In Script mode, we can write a complete program. Then we will save the file with “.py” extension and execute the file. So a complete program/file will be executed. The complete program is also called a Python script that is why it is called script mode. You should use Script mode for writing actual programs.

Comments

Popular posts from this blog

Python 4.4 - Points to remember

Python 3.6 - Points to remember

Python 3.3 - Datatypes in Python