x
Module: M3-R5: Python Programming
Chapter: Ch1 Computer Intro
Python library functions are **predefined functions** provided by Python libraries and modules. They save time and effort as you don’t need to write the code from scratch.
import math
print("Square root of 16:", math.sqrt(16))
print("Value of pi:", math.pi)
print("Factorial of 5:", math.factorial(5))
Output:
Square root of 16: 4.0
Value of pi: 3.141592653589793
Factorial of 5: 120
import random
print("Random number between 1 and 10:", random.randint(1, 10))
print("Random choice from list:", random.choice(['Python', 'C++', 'Java']))
Output:
Random number between 1 and 10: 7
Random choice from list: Python
import datetime
today = datetime.date.today()
now = datetime.datetime.now()
print("Today's Date:", today)
print("Current Time:", now)
Output:
Today's Date: 2025-10-19
Current Time: 2025-10-19 20:35:12.345678
import os
print("Current Working Directory:", os.getcwd())
print("List of files in current directory:", os.listdir())
Output:
Current Working Directory: /home/user
List of files in current directory: ['file1.py', 'file2.py', 'folder1']
import sys
print("Python Version:", sys.version)
print("System Path:", sys.path)
Output:
Python Version: 3.11.6 (default, ...)
System Path: ['...', '/usr/lib/python3.11', ...]
import statement.math, random, datetime, os, sys.