EMAIL SUPPORT
dclessons@dclessons.comLOCATION
AFPython Standard Library , Modules & Functions
Python Standard Library Overview
Python has rich set of standard Library, supply reusable modules which help python developer to work with data, Manipulate ZIP archive, highly complex functions etc. The standard Library contains Modules and which further contain Functions which are called in python code for specific task.
Let’s understand this with one example
Example 1: The Sys Module used as an example to know the Interpreter name of Python. Let’s see the example
>>> import sys >>> sys.platform ‘Windows NT’
Here in the above example, we are importing module sys, and then from module sys we are accessing its attributes called platform, which says that Windows NT is the name of your Interpreter.
Now let’s see how this Module is used further
Example 2
>>> import sys >>> print (sys.version) 3.4.3 (default, Nov 12 2018, 22:25:49) [GCC 4.8.4]
Here in above example, we are using another attributes of sys, which shows the Python Version that is 3.4.3
Example 3:
Let’s use datetime library, to work with data and time data. The date.today() function provides today’s date. Let’s see that.
>>> import datetime >>> datetime.date.today() datetime.date(2020, 12 , 12)
Even we can also able to see the day, month, year separately by using below function.
>>> datetime.date.today ().day 12 >>> datetime.date.today ().month 12 >>> datetime.date.today ().year 2020
Let’s suppose you want to see the time in Hours and minute, the Module time has to be imported and then its attributes can be called in to it to see the time.
>>> import time >>> time.strftime(“%H : %M”) ’13:48’
Here once we import the time module, call strftime() function and then specify how you want to see the time displayed. Let’s go with some deeper dive of datetime module
LEAVE A COMMENT
Please login here to comment.