Python Modules
Python Modules
Random
OS
Math
Datetime
Sys
PYTHON MODULES Aug 18, 2025
Random Module
#Random Module
import random
print(random.random())
print(random.uniform(1,10))
print(random.randint(1,10))
print(random.choice(['a','b','c']))
item =[7,3,2,5,6,4.1]
print(random.sample([1,2,3,4,5],3))
Output:
0.39764806498798044
5.033585626578608
5
b
[4, 5, 3]
PYTHON MODULES Aug 18, 2025
OS Module
#OS Module
import os
os.rename("eb.py","ebbill.py")
os.rename("fib.py","fibo.py")
os.remove("hello.py")
os.mkdir("test")
os.chdir("test")
x=os.getcwd()
print(“Current Directory",x)
os.chdir(“Z:\Python")
rmdir("test")
Output:
Current Directory Z:\Python\test
PYTHON MODULES Aug 18, 2025
Math Module
#Math Module
import math Output
print(math.ceil(4.5)) --- 5.0
print(math.fabs(-44)) --- 44.0
print(math.factorial(4)) --- 24
print(math.floor(4.3)) --- 4.0
print(math.fsum([0.1,0.2,1.2])) --- 1.5
print(math.e) ---
2.718281828459045
print(math.pi) ---
3.141592653589793
print(math.log(1024,2)) --- 10.0
print(math.cos(math.pi/4.0)) ---
0.707106781186547
print(math.sqrt(25)) --- 5.0
print(math.pow(2,3)) --- 8.0
PYTHON MODULES
print(math.trunc(80.23456)) --- Aug
80 18, 2025
Datetime Module
#Datetime Module
import datetime
t=datetime.time(07,12,03)
print(t)
print("Hour:",t.hour)
print("Minute:",t.minute)
print("Second:",t.second)
print("Micro second:",t.microsecond)
Output:
07:12:03
('Hour:', 7)
('Minute:', 12)
('Second:', 3)
('Micro second:', 0)
PYTHON MODULES Aug 18, 2025
Sys Module
#Sys Module
import sys
print("Number of args",len(sys.argv))
print("Argument list",str(sys.argv))
Output:
Number of args 1
Argument list ['Z:/Python/sys.py']
PYTHON MODULES Aug 18, 2025