Python provides functionality using library of modules.This is known as standard library.Before you use any library use the import statement.
For example to import string library use:
To import multiple modules use the following syntax:
import module1, module2
Accessing members of a module
to access a member of the module use the following syntax:
for example to get the current time you can use the datetime module.In the datetime module there is a datetime object which can be used to get the current system date and time.
to get the current date and time
Help on any Module
to get the help on any module use the help() method and pass it the module name.For example to get the information about the
datetime module use the following statement:
Similarly to get help about the string module use the following statements:
Shortcut for accessing members of a Module
Above we have used the following statement to display the current date and time
there is another way we can write the above statment which is much simpler:
from datetime import datetime
We use the from module-name import member name syntax to directly use the member name without using the module name to access the member name.
There are different modules in Python for different functionality.There are modules related to the different functionalities such as the following:
- data persistence
For example you can use the math module to perform different mathematical functions: