Page 446 - CITS - Computer Software Application -TT
P. 446
COMPUTER SOFTWARE APPLICATION - CITS
We may use the dot operator to use the functions using the module name. For instance:
Example:
1 # here, we are calling the module square method and passing the value 4
2 result = example_module.square( 4 )
3 print(“By using the module square of number is: “, result )
Output:
By using the module square of number is: 16
There are several standard modules for Python. The complete list of Python standard modules is available. The
list can be seen using the help command.
Similar to how we imported our module, a user-defined module, we can use an import statement to import other
standard modules.
Importing a module can be done in a variety of ways. Below is a list of them.
Python import Statement
Using the import Python keyword and the dot operator, we may import a standard module and can access the
defined functions within it. Here’s an illustration.
Code
1 # Here, we are creating a simple Python program to show how to import a standard module
2 # Here, we are import the math module which is a standard module
3 import math
4 print( “The value of euler’s number is”, math.e )
5 # here, we are printing the euler’s number from the math module
Output:
The value of euler’s number is 2.718281828459045
Python Date
Python provides the datetime module work with real dates and times. In real-world applications, we need to work
with the date and time. Python enables us to schedule our Python script to run at a particular timing.
In Python, the date is not a data type, but we can work with the date objects by importing the module named with
datetime, time, and calendar.
In this section of the tutorial, we will discuss how to work with the date and time objects in Python.
The datetime classes are classified in the six main classes.
• date - It is a naive ideal date. It consists of the year, month, and day as attributes.
• time - It is a perfect time, assuming every day has precisely 24*60*60 seconds. It has hour, minute, second,
microsecond, and tzinfo as attributes.
• datetime - It is a grouping of date and time, along with the attributes year, month, day, hour, minute, second,
microsecond, and tzinfo.
• timedelta - It represents the difference between two dates, time or datetime instances to microsecond
resolution.
• tzinfo - It provides time zone information objects.
• timezone - It is included in the new version of Python. It is the class that implements the tzinfo abstract base
class.
433
CITS : IT&ITES - Computer Software Application - Lesson 120 - 137 CITS : IT&ITES - Computer Software Application - Lesson 120 - 137