A Python Library என்பது particular tasks செய்ய தேவையான pre-written code, functions, classes, modules ஆகியவற்றின் collection.
நாமே எல்லா code-ஐயும் scratch-லிருந்து எழுதாமல், already created functions-ஐ பயன்படுத்த உதவுவது Python Library.
A Python Library என்பது particular tasks செய்ய தேவையான pre-written code, functions, classes, modules ஆகியவற்றின் collection. Simple definition: நாமே எல்லா code-ஐயும் scratch-லிருந்து எழுதாமல், already created functions-ஐ பயன்படுத்த உதவுவது…
A Python Library என்பது particular tasks செய்ய தேவையான pre-written code, functions, classes, modules ஆகியவற்றின் collection.
நாமே எல்லா code-ஐயும் scratch-லிருந்து எழுதாமல், already created functions-ஐ பயன்படுத்த உதவுவது Python Library.
1import math
1print(math.sqrt(25))
5.0
5.0
இங்கு square root calculate செய்ய algorithm நாமே எழுதவில்லை.
Python-ன் math module-ல் already இருக்கும்:
sqrt()
function-ஐ பயன்படுத்துகிறோம்.
ஒரு carpenter-க்கு toolbox இருக்கும்.
எல்லாம் ready-made tools.
அதே மாதிரி Python programmer-க்கு libraries/modules இருக்கும்.
math → Mathematical functions
random → Random values
statistics → Statistical calculations
datetime → Date and time
os → Operating system related operations
sys → Python/system related information
json → JSON data
csv → CSV files
re → Regular expressions
NumPy → Numerical computing
Pandas → Data analysis
Matplotlib → Graphs and charts
1Need square root 2↓ 3Use math 4↓ 5import math 6↓ 7math.sqrt(25) 8↓ 95.0
1Basic Import 2import library_name
1import math 2Using a Function 3library_name.function_name()
1math.sqrt(25) 2Import Specific Function 3from library_name import function_name
1from math import sqrt
1print(sqrt(25)) 2Import with Alias 3import library_name as alias
1import numpy as np
np → Alias
numpy → Original library name
1Using math 2import math
1x = 25
1result = math.sqrt(x)
1print(result)
5.0
5.0
| Step | Statement | x | result | Output |
|---|---|---|---|---|
| 01Iteration 1 | import math | - | - | - |
| 02Iteration 2 | x = 25 | 25 | - | - |
| 03Iteration 3 | math.sqrt(x) | 25 | 5.0 | - |
| 04Iteration 4 | print(result) | 25 | 5.0 | 5.0 |
A module என்பது Python code இருக்கும் ஒரு file.
1import math
math ஒரு module.
Python-லும் different modules different வேலைகளுக்காக இருக்கும்.
| Term | Simple Meaning |
|---|---|
| Module | ஒரு Python code unit/file |
| Package | பல related modules-ன் collection |
| Library | reusable code collection என்ற broad term |
| Simple memory: | Module |
| ↓ | Small unit |
| Package | ↓ |
| Collection of modules | Library |
| ↓ | Ready-made functionality |
Students basic level-ல் math library, random library என்று சொல்லலாம்.
math, random, statistics போன்றவை Python Standard Library-ல் உள்ள modules.
Python install செய்தவுடன் available ஆகும் large collection of modules-ஐ Python Standard Library என்று கூறுகிறோம்.
பல modules-க்கு separate installation தேவையில்லை.
Standard Library = Python உடன் வரும் ready-made tools
math module mathematical calculations செய்ய useful.
import math
| Function | Purpose |
|---|---|
| math.sqrt() | Square root |
| math.pow() | Power |
| math.ceil() | Round upward |
| math.floor() | Round downward |
| math.factorial() | Factorial |
| math.sin() | Sine |
| math.cos() | Cosine |
| math.log() | Logarithm |
math.pi
math.e
1Square Root 2import math
1print(math.sqrt(64))
8.0
8.0
1Power 2import math
1print(math.pow(2, 3))
8.0
8.0
1Pi 2import math
1print(math.pi)
3.141592653589793
1Ceiling and Floor 2import math
1x = 4.7
1print(math.ceil(x)) 2print(math.floor(x))
5 4
5 4
math.ceil(4.7)
means
5
math.floor(4.7)
4
1Factorial 2import math
1print(math.factorial(5))
120
120
Because:
5! = 5 × 4 × 3 × 2 × 1
= 120
random module pseudo-random values generate செய்ய பயன்படுகிறது.
import random
Dice throw பண்ணினால் எந்த number வரும் என்று முன்னதாக exact-ஆ தெரியாது.
random
module use செய்யலாம்.
1Random Integer 2import random
1x = random.randint(1, 6)
1print(x)
4
4
2
6
வரலாம்.
random.randint(1, 6)
1 முதல் 6 வரை inclusive random integer.
1
and
6
can occur.
1Random Choice 2import random
names = ["Arun", "Bala", "Kumar"]
1print(random.choice(names))
Bala
Bala
| Function | Purpose |
|---|---|
| random.random() | Random float from 0.0 up to, but not including, 1.0 |
| random.randint(a,b) | Random integer from a to b inclusive |
| random.choice() | Choose one item |
| random.shuffle() | Shuffle items |
random.randint(1, 5) means only 1 to 4 என்று நினைக்க வேண்டாம்.
Correct:
1, 2, 3, 4, 5
all possible.
statistics module basic statistical calculations செய்ய பயன்படுகிறது.
import statistics
1import statistics
marks = [80, 90, 70, 100]
1print(statistics.mean(marks))
85
85
80 + 90 + 70 + 100 = 340
4
340 / 4 = 85
1Median 2import statistics
data = [10, 20, 30, 40, 50]
1print(statistics.median(data))
30
30
1Mode 2import statistics
data = [10, 20, 20, 30]
1print(statistics.mode(data))
20
20
Because 20 occurs most frequently.
datetime module date and time operations செய்ய பயன்படுகிறது.
1import datetime
1today = datetime.date.today()
1print(today)
2026-08-11
Current date
Current time
Date difference
Age calculations
Scheduling applications
Logging
os module operating system related functionality access செய்ய பயன்படுகிறது.
import os
1Current Working Directory 2import os
1print(os.getcwd())
C:\Users\Admin\Documents
C:\Users\Admin\Documents
Files
Folders
Paths
Environment variables
Current working directory
sys module Python interpreter மற்றும் runtime environment related information/functionality access செய்ய பயன்படுகிறது.
1import sys
1print(sys.version)
3.x.x ...
3.x.x ...
sys.version
→ Python version information
sys.argv
→ Command-line arguments
sys.exit()
→ Program exit
json module JSON data-ஐ Python data-ஆக convert செய்யவும், Python data-ஐ JSON format-ஆக convert செய்யவும் பயன்படுகிறது.
1import json
1student = { 2 "name": "Arun", 3 "mark": 90 4}
1result = json.dumps(student)
1print(result)
{"name": "Arun", "mark": 90}
{"name": "Arun", "mark": 90}
csv module CSV files read/write செய்ய பயன்படுகிறது.
Comma-Separated Values
Regular Expression
Text pattern search மற்றும் matching செய்ய பயன்படுகிறது.
1import re
text = "My number is 12345"
1result = re.findall(r"\d+", text)
1print(result)
['12345']
['12345']
Python-உடன் default installation-ல் எல்லா external libraries-மும் வராது.
Some libraries separately install செய்ய வேண்டும்.
pip install numpy
pip install library_name
Then:
1import numpy
NumPy என்பது numerical computing மற்றும் arrays-க்கு widely used Python library.
Numerical Python
import numpy as np
1import numpy as np
1numbers = np.array([10, 20, 30])
1print(numbers)
[10 20 30]
[10 20 30]
Arrays
Matrix operations
Mathematical calculations
Scientific computing
Machine learning foundations
Pandas என்பது structured/table data analysis மற்றும் manipulation செய்ய பயன்படும் popular Python library.
import pandas as pd
1import pandas as pd
1data = { 2 "Name": ["Arun", "Bala"], 3 "Mark": [90, 85] 4}
1df = pd.DataFrame(data)
1print(df)
Name Mark 0 Arun 90 1 Bala 85
Name Mark 0 Arun 90 1 Bala 85
Series
DataFrame
Matplotlib என்பது graphs, plots மற்றும் charts உருவாக்க பயன்படும் visualization library.
import matplotlib.pyplot as plt
1import matplotlib.pyplot as plt
x = [1, 2, 3] y = [10, 20, 30]
plt.plot(x, y) plt.show()
This displays a line graph.
Line graph
Bar chart
Pie chart
Scatter plot
Data visualization
| Library / Module | Main Purpose |
|---|---|
| math | Mathematical functions |
| random | Random values |
| statistics | Mean, median, mode |
| datetime | Date and time |
| os | Operating system tasks |
| sys | Python/system information |
| json | JSON processing |
| csv | CSV files |
| re | Pattern matching |
| NumPy | Arrays and numerical computing |
| Pandas | Data analysis |
| Matplotlib | Graphs and charts |
| Point | Standard Library | Third-Party Library |
|---|---|---|
| Availability | Comes with Python distribution | Usually installed separately |
| Installation | Usually no extra pip installation | Often pip install required |
| Example | math | NumPy |
| Example | random | Pandas |
| Example | datetime | Matplotlib |
import Statement
import math
math.sqrt(25)
module.function()
1Method 1 2import math
1print(math.sqrt(25)) 2Method 2 3from math import sqrt
1print(sqrt(25))
Here math. prefix தேவையில்லை.
1Method 3 - Alias 2import math as m
1print(m.sqrt(25))
NameError
m என்பது alias.
| Method | Example | Function Call |
|---|---|---|
| Normal import | import math | math.sqrt(25) |
| Specific import | from math import sqrt | sqrt(25) |
| Alias | import math as m | m.sqrt(25) |
Library import செய்யாமல் function call செய்வது
print(math.sqrt(25))
import math
NameError
1import math
1print(math.sqrt(25))
Wrong Function Name
math.squareroot(25)
math.sqrt(25)
Case mistake
Python is case-sensitive.
Math.sqrt(25)
math.sqrt(25)
Alias பயன்படுத்திய பிறகு original alias form confuse செய்வது
import numpy as np
Then normally:
np.array([1, 2, 3])
Use the imported name np.
Module and Function confuse செய்வது
import math
math → module
math.sqrt()
sqrt → function
M R S D O S J C R
M → Math
R → Random
S → Statistics
D → Datetime
O → OS
S → Sys
J → JSON
C → CSV
R → Regular Expression
N P M
N → NumPy
P → Pandas
M → Matplotlib
A library provides reusable code for common programming tasks.
Python uses the import statement to access modules.
math provides mathematical functions.
math.sqrt()
calculates square root.
math.factorial()
calculates factorial.
random is used for pseudo-random values.
random.randint(a, b)
returns a random integer between a and b, inclusive.
statistics.mean() calculates arithmetic mean.
datetime handles dates and times.
os provides operating-system-related functionality.
sys.version provides Python version information.
json is used for JSON encoding and decoding.
csv supports CSV file processing.
re supports regular expressions.
NumPy is mainly associated with numerical arrays and scientific computing.
Pandas is widely used for data analysis.
Matplotlib is widely used for plotting and data visualization.
What is a Python library?
Answer
A Python library is a collection of reusable code that provides functions, classes, and modules for performing particular tasks without writing everything from scratch.
What is the Python Standard Library?
Answer
The Python Standard Library is a collection of modules distributed with Python that provide functionality such as mathematics, file handling, dates, JSON processing, and operating-system interaction.
What is the purpose of import?
Answer
The import statement makes a module or its contents available for use in the current program.
What is the difference between math and NumPy?
Answer
math mainly provides mathematical functions for ordinary numeric values. NumPy provides powerful multidimensional arrays and vectorized numerical operations for scientific and data-oriented computing.
Why do we use aliases?
Answer
Aliases provide shorter or conventional names for modules.
1import numpy as np
12.0
Use math to find:
√144
Answer:
import math
print(math.sqrt(144))
12.0
Find:
6!
1import math
1print(math.factorial(6))
720
720
Generate a random integer between 1 and 10.
import random
print(random.randint(1, 10))
Calculate mean:
marks = [80, 70, 90, 100]
Use:
import statistics
print(statistics.mean(marks))
Answer:
85
Print Python version using sys.
import sys
print(sys.version)
Print current working directory.
import os
print(os.getcwd())
Create a NumPy array:
[10, 20, 30, 40]
Answer:
import numpy as np
x = np.array([10, 20, 30, 40]) print(x)
Identify the correct library:
Answers:
Matplotlib
Pandas
NumPy
random
math