Introduces key libraries TRB CSI › Python Programming › Introduces key libraries

Introduces key libraries

A Python Library என்பது particular tasks செய்ய தேவையான pre-written code, functions, classes, modules ஆகியவற்றின் collection. Simple definition: நாமே எல்லா code-ஐயும் scratch-லிருந்து எழுதாமல், already created functions-ஐ பயன்படுத்த உதவுவது…

Free Beginner 27 min 224 cards 68 programs 18 MCQs v2
Definition
Meaning

A Python Library என்பது particular tasks செய்ய தேவையான pre-written code, functions, classes, modules ஆகியவற்றின் collection.

நாமே எல்லா code-ஐயும் scratch-லிருந்து எழுதாமல், already created functions-ஐ பயன்படுத்த உதவுவது Python Library.

Program
Example
Python 1 lines
1import math
Program
Python 1 lines
1print(math.sqrt(25))
Verified output
5.0
Learning Run Mode — this is the output the author verified, not a live execution.
Output
5.0

இங்கு square root calculate செய்ய algorithm நாமே எழுதவில்லை.

Python-ன் math module-ல் already இருக்கும்:

sqrt()

function-ஐ பயன்படுத்துகிறோம்.

Simple Explanation
Core idea

ஒரு carpenter-க்கு toolbox இருக்கும்.

Toolbox-ல்
  • Hammer
  • Screwdriver
  • Spanner
  • Cutter
Detail 02

எல்லாம் ready-made tools.

Detail 03

அதே மாதிரி Python programmer-க்கு libraries/modules இருக்கும்.

For example

math → Mathematical functions

Detail 05

random → Random values

Detail 06

statistics → Statistical calculations

Detail 07

datetime → Date and time

Detail 08

os → Operating system related operations

Detail 09

sys → Python/system related information

Detail 10

json → JSON data

Detail 11

csv → CSV files

Detail 12

re → Regular expressions

Detail 13

NumPy → Numerical computing

Detail 14

Pandas → Data analysis

Detail 15

Matplotlib → Graphs and charts

Flow
  1. Problem / Task
  2. Required library identify செய்கிறோம்
  3. Library import செய்கிறோம்
  4. Required function call செய்கிறோம்
  5. Python executes library code
  6. Result கிடைக்கும்
Program
Example
Python 9 lines
1Need square root
2
3Use math
4
5import math
6
7math.sqrt(25)
8
95.0
Syntax
Python 2 lines
1Basic Import
2import library_name
Program
Example
Python 3 lines
1import math
2Using a Function
3library_name.function_name()
Program
Example
Python 3 lines
1math.sqrt(25)
2Import Specific Function
3from library_name import function_name
Program
Example
Python 1 lines
1from math import sqrt
Program
Python 3 lines
1print(sqrt(25))
2Import with Alias
3import library_name as alias
Program
Example
Python 1 lines
1import numpy as np
Explanation
Core idea

np → Alias

Here

numpy → Original library name

Program
Program 1
Python 2 lines
1Using math
2import math
Program
Python 1 lines
1x = 25
Program
Python 1 lines
1result = math.sqrt(x)
Program
Python 1 lines
1print(result)
Verified output
5.0
Learning Run Mode — this is the output the author verified, not a live execution.
Output
5.0
Line by Line
1
import math
Python-ன் math module-ஐ program-க்கு available ஆக்குகிறது.
2
x = 25
x variable-க்கு 25 assign செய்கிறோம்.
3
result = math.sqrt(x)
math.sqrt() square root calculate செய்யும் function. So: √25 = 5 Python result: 5.0
4
print(result)
Calculated result screen-ல் display ஆகிறது.
Dry Run
Execution traceRead top to bottom · highlighted cells show the current value4 states
StepStatementxresultOutput
01Iteration 1import math---
02Iteration 2x = 2525--
03Iteration 3math.sqrt(x)255.0-
04Iteration 4print(result)255.05.0

Definition
Meaning

A module என்பது Python code இருக்கும் ஒரு file.

  • Functions
  • Variables
  • Classes
  • Constants
  • இருக்கலாம்.
Program
Example
Python 1 lines
1import math
Explanation
Core idea

math ஒரு module.

Simple Explanation
Core idea

Python-லும் different modules different வேலைகளுக்காக இருக்கும்.

ஒரு notebook-ல் ஒரு particular subject notes இருப்பது போல
  • Math notebook
  • Science notebook
  • English notebook

Comparison
TermSimple Meaning
Moduleஒரு Python code unit/file
Packageபல related modules-ன் collection
Libraryreusable code collection என்ற broad term
Comparison
Simple memory:Module
Small unit
Package
Collection of modulesLibrary
Ready-made functionality
Important
  1. Students basic level-ல் math library, random library என்று சொல்லலாம்.

  2. Technically

    math, random, statistics போன்றவை Python Standard Library-ல் உள்ள modules.

Definition
Meaning

Python install செய்தவுடன் available ஆகும் large collection of modules-ஐ Python Standard Library என்று கூறுகிறோம்.

பல modules-க்கு separate installation தேவையில்லை.

  • math
  • random
  • statistics
  • datetime
  • os
  • sys
  • json
  • csv
  • re
Memory Trick

Standard Library = Python உடன் வரும் ready-made tools

Definition
Meaning

math module mathematical calculations செய்ய useful.

import math

Table
Common math functions
FunctionPurpose
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
Important
  1. Important constants

    math.pi

  2. math.e

Program
Python 2 lines
1Square Root
2import math
Program
Python 1 lines
1print(math.sqrt(64))
Verified output
8.0
Learning Run Mode — this is the output the author verified, not a live execution.
Output
8.0
Program
Python 2 lines
1Power
2import math
Program
Python 1 lines
1print(math.pow(2, 3))
Verified output
8.0
Learning Run Mode — this is the output the author verified, not a live execution.
Output
8.0
Program
Python 2 lines
1Pi
2import math
Program
Python 1 lines
1print(math.pi)
Explanation
Output approximately

3.141592653589793

Program
Python 2 lines
1Ceiling and Floor
2import math
Program
Python 1 lines
1x = 4.7
Program
Python 2 lines
1print(math.ceil(x))
2print(math.floor(x))
Verified output
5
4
Learning Run Mode — this is the output the author verified, not a live execution.
Output
5
4
Explanation

math.ceil(4.7)

means

4.7-க்கு next higher integer

5

math.floor(4.7)

4.7-க்கு lower integer

4

Program
Python 2 lines
1Factorial
2import math
Program
Python 1 lines
1print(math.factorial(5))
Verified output
120
Learning Run Mode — this is the output the author verified, not a live execution.
Output
120

Because:

5! = 5 × 4 × 3 × 2 × 1
= 120

Definition
Meaning

random module pseudo-random values generate செய்ய பயன்படுகிறது.

import random

Simple Explanation
Core idea

Dice throw பண்ணினால் எந்த number வரும் என்று முன்னதாக exact-ஆ தெரியாது.

அதே மாதிரி random number generate செய்ய

random

Detail 02

module use செய்யலாம்.

Program
Python 2 lines
1Random Integer
2import random
Program
Python 1 lines
1x = random.randint(1, 6)
Program
Python 1 lines
1print(x)
Verified output
4
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Possible output
4

2

6

வரலாம்.

Important
  1. random.randint(1, 6)

  2. means

    1 முதல் 6 வரை inclusive random integer.

  3. Both

    1

  4. and

  5. 6

  6. can occur.

Program
Python 2 lines
1Random Choice
2import random
Explanation
Core idea

names = ["Arun", "Bala", "Kumar"]

Program
Python 1 lines
1print(random.choice(names))
Verified output
Bala
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Possible output
Bala
Table
Common random functions
FunctionPurpose
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
Common Mistake

random.randint(1, 5) means only 1 to 4 என்று நினைக்க வேண்டாம்.

Correct:

1, 2, 3, 4, 5

all possible.

Definition
Meaning

statistics module basic statistical calculations செய்ய பயன்படுகிறது.

  • Mean
  • Median
  • Mode

import statistics

Program
Python 1 lines
1import statistics
Explanation
Core idea

marks = [80, 90, 70, 100]

Program
Python 1 lines
1print(statistics.mean(marks))
Verified output
85
Learning Run Mode — this is the output the author verified, not a live execution.
Output
85
Explanation
Values

80 + 90 + 70 + 100 = 340

Number of values

4

Mean

340 / 4 = 85

Program
Python 2 lines
1Median
2import statistics
Explanation
Core idea

data = [10, 20, 30, 40, 50]

Program
Python 1 lines
1print(statistics.median(data))
Verified output
30
Learning Run Mode — this is the output the author verified, not a live execution.
Output
30
Program
Python 2 lines
1Mode
2import statistics
Explanation
Core idea

data = [10, 20, 20, 30]

Program
Python 1 lines
1print(statistics.mode(data))
Verified output
20
Learning Run Mode — this is the output the author verified, not a live execution.
Output
20

Because 20 occurs most frequently.

Definition
Meaning

datetime module date and time operations செய்ய பயன்படுகிறது.

Program
Python 1 lines
1import datetime
Program
Python 1 lines
1today = datetime.date.today()
Program
Python 1 lines
1print(today)
Explanation
Output will be the current system date in a form such as

2026-08-11

Important
  1. datetime useful for

    Current date

  2. Current time

  3. Date difference

  4. Age calculations

  5. Scheduling applications

  6. Logging

Definition
Meaning

os module operating system related functionality access செய்ய பயன்படுகிறது.

import os

Program
Python 2 lines
1Current Working Directory
2import os
Program
Python 1 lines
1print(os.getcwd())
Verified output
C:\Users\Admin\Documents
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Possible output
C:\Users\Admin\Documents
Important
  1. os module can help with

    Files

  2. Folders

  3. Paths

  4. Environment variables

  5. Current working directory

Definition
Meaning

sys module Python interpreter மற்றும் runtime environment related information/functionality access செய்ய பயன்படுகிறது.

Program
Python 1 lines
1import sys
Program
Python 1 lines
1print(sys.version)
Verified output
3.x.x ...
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Possible output
3.x.x ...
Important
  1. Common

    sys.version

  2. → Python version information

  3. sys.argv

  4. → Command-line arguments

  5. sys.exit()

  6. → Program exit

Definition
Meaning

json module JSON data-ஐ Python data-ஆக convert செய்யவும், Python data-ஐ JSON format-ஆக convert செய்யவும் பயன்படுகிறது.

  • Web applications
  • APIs
  • Mobile apps
  • Data exchange
Program
Python 1 lines
1import json
Program
Python 4 lines
1student = {
2    "name": "Arun",
3    "mark": 90
4}
Program
Python 1 lines
1result = json.dumps(student)
Program
Python 1 lines
1print(result)
Verified output
{"name": "Arun", "mark": 90}
Learning Run Mode — this is the output the author verified, not a live execution.
Output
{"name": "Arun", "mark": 90}

Definition
Meaning

csv module CSV files read/write செய்ய பயன்படுகிறது.

Comma-Separated Values

Explanation
Example
Core idea
  • Name,Mark
  • Arun,90
  • Bala,85
CSV commonly used for
  • Student data
  • Reports
  • Excel-compatible data exchange
  • Datasets

Definition

Regular Expression

Text pattern search மற்றும் matching செய்ய பயன்படுகிறது.

Program
Python 1 lines
1import re
Explanation
Core idea

text = "My number is 12345"

Program
Python 1 lines
1result = re.findall(r"\d+", text)
Program
Python 1 lines
1print(result)
Verified output
['12345']
Learning Run Mode — this is the output the author verified, not a live execution.
Output
['12345']
Simple Explanation
re useful for
  • Phone number validation
  • Email pattern validation
  • Search
  • Text processing
  • Data cleaning

Third-Party Libraries

Context

Python-உடன் default installation-ல் எல்லா external libraries-மும் வராது.

Some libraries separately install செய்ய வேண்டும்.

  • NumPy
  • Pandas
  • Matplotlib
  • SciPy
  • Requests
Explanation
Core idea

pip install numpy

Installation generally

pip install library_name

Detail 02

Then:

Program
Python 1 lines
1import numpy

Definition
Meaning

NumPy என்பது numerical computing மற்றும் arrays-க்கு widely used Python library.

Numerical Python

import numpy as np

Program
Python 1 lines
1import numpy as np
Program
Python 1 lines
1numbers = np.array([10, 20, 30])
Program
Python 1 lines
1print(numbers)
Verified output
[10 20 30]
Learning Run Mode — this is the output the author verified, not a live execution.
Output
[10 20 30]
Important
  1. NumPy useful for

    Arrays

  2. Matrix operations

  3. Mathematical calculations

  4. Scientific computing

  5. Machine learning foundations

Definition
Meaning

Pandas என்பது structured/table data analysis மற்றும் manipulation செய்ய பயன்படும் popular Python library.

import pandas as pd

Program
Python 1 lines
1import pandas as pd
Program
Python 4 lines
1data = {
2    "Name": ["Arun", "Bala"],
3    "Mark": [90, 85]
4}
Program
Python 1 lines
1df = pd.DataFrame(data)
Program
Python 1 lines
1print(df)
Verified output
Name  Mark
0  Arun    90
1  Bala    85
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Possible output
Name  Mark
0  Arun    90
1  Bala    85
Important
  1. Pandas main structures

    Series

  2. DataFrame

Definition
Meaning

Matplotlib என்பது graphs, plots மற்றும் charts உருவாக்க பயன்படும் visualization library.

import matplotlib.pyplot as plt

Program
Python 1 lines
1import matplotlib.pyplot as plt
Explanation
Core idea
x = [1, 2, 3]
y = [10, 20, 30]
Detail 01
plt.plot(x, y)
plt.show()
Detail 02

This displays a line graph.

Important
  1. Matplotlib useful for

    Line graph

  2. Bar chart

  3. Pie chart

  4. Scatter plot

  5. Data visualization

Comparison
Important Libraries at a Glance
Library / ModuleMain Purpose
mathMathematical functions
randomRandom values
statisticsMean, median, mode
datetimeDate and time
osOperating system tasks
sysPython/system information
jsonJSON processing
csvCSV files
rePattern matching
NumPyArrays and numerical computing
PandasData analysis
MatplotlibGraphs and charts
Comparison
Standard Library vs Third-Party Library
PointStandard LibraryThird-Party Library
AvailabilityComes with Python distributionUsually installed separately
InstallationUsually no extra pip installationOften pip install required
ExamplemathNumPy
ExamplerandomPandas
ExampledatetimeMatplotlib
Important
  1. import Statement

  2. To use a module

    import math

  3. Then

    math.sqrt(25)

  4. Notice

    module.function()

Different Ways of Importing

Program
Python 2 lines
1Method 1
2import math
Program
Python 3 lines
1print(math.sqrt(25))
2Method 2
3from math import sqrt
Program
Python 1 lines
1print(sqrt(25))

Here math. prefix தேவையில்லை.

Program
Python 2 lines
1Method 3 - Alias
2import math as m
Program
Python 1 lines
1print(m.sqrt(25))
Verified output
NameError
Learning Run Mode — this is the output the author verified, not a live execution.

m என்பது alias.

Comparison
MethodExampleFunction Call
Normal importimport mathmath.sqrt(25)
Specific importfrom math import sqrtsqrt(25)
Aliasimport math as mm.sqrt(25)
Common Mistake
Error 1
Context

Library import செய்யாமல் function call செய்வது

print(math.sqrt(25))

import math

Output
Possible result
NameError
Program
Correct
Python 1 lines
1import math
Program
Python 1 lines
1print(math.sqrt(25))
Common Mistake
Error 2
Context

Wrong Function Name

math.squareroot(25)

math.sqrt(25)

Common Mistake
Error 3
Context

Case mistake

Python is case-sensitive.

Math.sqrt(25)

math.sqrt(25)

Common Mistake
Error 4

Alias பயன்படுத்திய பிறகு original alias form confuse செய்வது
import numpy as np

Then normally:

np.array([1, 2, 3])

Use the imported name np.

Common Mistake
Error 5

Module and Function confuse செய்வது
import math

math → module

math.sqrt()

sqrt → function

Remember
  1. M R S D O S J C R

  2. M → Math

  3. R → Random

  4. S → Statistics

  5. D → Datetime

  6. O → OS

  7. S → Sys

  8. J → JSON

  9. C → CSV

  10. R → Regular Expression

  11. For Data Science

    N P M

  12. N → NumPy

  13. P → Pandas

  14. M → Matplotlib

TRB Point
TRB Point 1

A library provides reusable code for common programming tasks.

TRB Point
TRB Point 2

Python uses the import statement to access modules.

TRB Point
TRB Point 3

math provides mathematical functions.

TRB Point
TRB Point 4
  1. math.sqrt()

  2. calculates square root.

TRB Point
TRB Point 5
  1. math.factorial()

  2. calculates factorial.

TRB Point
TRB Point 6

random is used for pseudo-random values.

TRB Point
TRB Point 7
  1. random.randint(a, b)

  2. returns a random integer between a and b, inclusive.

TRB Point
TRB Point 8

statistics.mean() calculates arithmetic mean.

TRB Point
TRB Point 9

datetime handles dates and times.

TRB Point
TRB Point 10

os provides operating-system-related functionality.

TRB Point
TRB Point 11

sys.version provides Python version information.

TRB Point
TRB Point 12

json is used for JSON encoding and decoding.

TRB Point
TRB Point 13

csv supports CSV file processing.

TRB Point
TRB Point 14

re supports regular expressions.

TRB Point
TRB Point 15

NumPy is mainly associated with numerical arrays and scientific computing.

TRB Point
TRB Point 16

Pandas is widely used for data analysis.

TRB Point
TRB Point 17

Matplotlib is widely used for plotting and data visualization.

Interview Point
Question 1

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.

Interview Point
Question 2

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.

Interview Point
Question 3

What is the purpose of import?

Answer

The import statement makes a module or its contents available for use in the current program.

Interview Point
Question 4

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.

Interview Point
Question 5

Why do we use aliases?

Answer

Aliases provide shorter or conventional names for modules.

Program
Example
Python 1 lines
1import numpy as np
Verified output
12.0
Learning Run Mode — this is the output the author verified, not a live execution.
MCQ
193Which keyword is used to load a Python module?
Choose one answer
MCQ
194Which module provides mathematical functions?
Choose one answer
MCQ
195What is the output? import math print(math.sqrt(81))
Choose one answer
MCQ
196Which function calculates factorial?
Choose one answer
MCQ
197Which module can generate random numbers?
Choose one answer
MCQ
198What values may this generate? random.randint(1, 3)
Choose one answer
MCQ
199Which module contains mean()?
Choose one answer
MCQ
200Which module is mainly used with dates and times?
Choose one answer
MCQ
201What does os.getcwd() commonly return?
Choose one answer
MCQ
202Which expression gives Python version information?
Choose one answer
MCQ
203JSON processing is mainly provided by:
Choose one answer
MCQ
204CSV stands for:
Choose one answer
MCQ
205Which library is widely used for arrays?
Choose one answer
MCQ
206The conventional alias for NumPy is:
Choose one answer
MCQ
207Which library is widely used for tabular data analysis?
Choose one answer
MCQ
208Which library is commonly imported as: import matplotlib.pyplot as plt
Choose one answer
MCQ
209What is sqrt in this statement? math.sqrt(25)
Choose one answer
MCQ
210What is math here? import math
Choose one answer
Practice
Practice 1

Use math to find:

√144

Answer:

import math

print(math.sqrt(144))

Output
12.0
Practice
Practice 2

Find:

6!

Program
Python 1 lines
1import math
Program
Python 1 lines
1print(math.factorial(6))
Verified output
720
Learning Run Mode — this is the output the author verified, not a live execution.
Output
Expected output
720
Practice
Practice 3

Generate a random integer between 1 and 10.

import random

print(random.randint(1, 10))

Practice
Practice 4

Calculate mean:

marks = [80, 70, 90, 100]

Use:

import statistics

print(statistics.mean(marks))

Answer:

85

Practice
Practice 5

Print Python version using sys.

import sys

print(sys.version)

Practice
Practice 6

Print current working directory.

import os

print(os.getcwd())

Practice
Practice 7

Create a NumPy array:

[10, 20, 30, 40]

Answer:

import numpy as np

x = np.array([10, 20, 30, 40])

print(x)
Practice
Practice 8

Identify the correct library:

Graph
?
Table data
?
Arrays
?
Random number
?
Square root
?

Answers:

Matplotlib
Pandas
NumPy
random
math

Summary
  1. Python libraries/modules providereusable ready-made code.
  2. importis used to access modules.
  3. math provides mathematicalfunctions.
  4. random generates pseudo-randomvalues.
  5. statistics provides statisticalcalculations.
  6. datetimeworks with date and time.
  7. osworks with operating-system-related functionality.
  8. sys provides Python/runtimeinformation.
  9. json processes JSON.
  10. csv processes CSV files.
  11. re provides regular-expressionsupport.
  12. NumPy provides powerful arrays andnumerical computing.
  13. Pandasis widely used for data analysis.
  14. Matplotlibis widely used for visualization.
  15. import library as aliascreates an alias.
  16. Standard Library modules generallycome with Python.
  17. Third-party libraries commonlyrequire separate installation.
Quick Revision
  1. Library → Ready-made reusable code
  2. Module → Python code unit/module
  3. import → Load/use module
  4. math → Mathematics
  5. sqrt() → Square root
  6. factorial() → Factorial
  7. random → Random values
  8. randint() → Random integer
  9. statistics → Mean, median, mode
  10. datetime → Date and time
  11. os → Operating system
  12. sys → Python/system information
  13. json → JSON data
  14. csv → CSV files
  15. re → Regular expressions
  16. NumPy → Numerical arrays
  17. Pandas → Data analysis
  18. Matplotlib → Graphs
  19. np → Common NumPy alias
  20. pd → Common Pandas alias
  21. plt → Common Matplotlib pyplotalias
  22. Easy Memory: Math = Calculate,Random = Generate, Statistics = Analyze, NumPy = Numbers, Pandas = Data, Matplotlib = Graph.
Text size
17px
Theme
Contents
Print / PDF
Program