Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

What Is Python Module

The document discusses three Python modules: 1) The random module generates random float and integer values for use in programs. 2) The datetime module handles date and time objects and allows manipulation of dates, times, and time intervals. It includes classes like Date, Time, Datetime, and Timedelta. 3) The math module provides common mathematical functions and is imported to use functions like square root.

Uploaded by

Aarathi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

What Is Python Module

The document discusses three Python modules: 1) The random module generates random float and integer values for use in programs. 2) The datetime module handles date and time objects and allows manipulation of dates, times, and time intervals. It includes classes like Date, Time, Datetime, and Timedelta. 3) The math module provides common mathematical functions and is imported to use functions like square root.

Uploaded by

Aarathi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

IMPORTED PACKAGES

A Python module is a file containing Python definitions and statements.


A module can define functions, classes, and variables. A module can also
include runnable code. Grouping related code into a module makes the code
easier to understand and use. It also makes the code logically organized.
1. RANDOM MODULE:
Random module is used to generate random float values. This is done by
using random.random() method that helps generate a random float value
ranging from 0.0 to 1.0. There are no arguments required for the function.
Example:
import random

print('Printing random number using random.random():')


print(random.random())

OUTPUT:

Printing random number using random.random():


0.909824521137017

In Python, the randint() method is used to generate a random number between


the supplied integers. The random module defines this function. The syntax of
this function is:

random.randint(a, b)

import random

print('Random number:', random.randint(0,10))


print('Random number:', random.randint(0,50))
print('Random number:', random.randint(0,100))
Output:

Random number: 5
Random number: 32
Random number: 84

2. DATE TIME MODULE:

In Python, date and time are not a data type of their own, but a module named
datetime can be imported to work with the date as well as time. Python
Datetime module comes built into Python, so there is no need to install it
externally.
Python Datetime module supplies classes to work with date and time. These
classes provide a number of functions to deal with dates, times and time
intervals. Date and datetime are an object in Python, so when you manipulate
them, you are actually manipulating objects and not string or timestamps.

The DateTime module is categorized into 6 main classes:


i. Date – An idealized naive date, assuming the current Gregorian calendar
always was, and always will be, in effect. Its attributes are year, month and
day.
ii. Time – An idealized time, independent of any particular day, assuming that
every day has exactly 24*60*60 seconds. Its attributes are hour, minute,
second, microsecond, and tzinfo
iii. Datetime – It’s a combination of date and time along with the attributes
year, month, day, hour, minute, second, microsecond, and tzinfo.
iv. Timedelta – A duration expressing the difference between two dates, time,
or datetime instances to microsecond resolution.
v. Tzinfo – It provides time zone information objects.
vi. Timezone – A class that implements the tzinfo abstract base class as a fixed
offset from the UTC (New in version 3.2).

3. MATH MODULE:
The math module is a standard module in Python and is always available.
To use mathematical functions under this module, you have to import the
module using import math.
Example:
Square root calculation import math math.sqrt(4)
BIBLIOGRAPHY
➢ Google.com
➢ Youtube.com
➢ Sunita arora class 11th ip book
➢ www.wikipedia.com

You might also like