Python Programming - 2026 Batch
Python Programming - 2026 Batch
• igjd; vd;gJ xU cau;kl;l (High Level), Interpreted, nghJ Nehf;f fzpdp nra;epuy;
nkhopahFk;. ,k; nkhopahdJ Guido van Rossum vd;gtuhy; cUthf;fg;gl;lJ. (The first
release was in 1991).
Characteristics of Python
1. Easy-to-learn (fw;gjw;F ,yF)
2. Easy-to-read (thrpg;gjw;F ,yF)
3. Easy-to-Maintain (guhkupj;jy; ,yF)
4. A broad standard library (gue;j mstpyhd gy library cs;sd)
5. Portable - igjd; gue;j mstpyhd td;nghUs; jsq;fspy; ,aq;ff;$baJ. mj;Jld;
midj;J ,aq;Fjsq;fspYk; xNu tpjkhd ,ilKfj;ijf; nfhz;Ls;sJ.
6. GUI Programming - Python supports GUI applications that can be created and ported to many
system calls, libraries and windows systems, such as Windows MFC, Macintosh, and the X
Window system of Unix.
Variables (khwpfs;)
• juTfis epidtfj;jpy; jw;fhypfkhf Nrkpj;J itg;gjw;fhf gad;gLj;jg;gLk; ngau;fs;
khwpfs; vdg;gLk;.
A variable is a name that stores a value which can change during program execution.
• x = 10
x = 20
1 of 87
Constants/ Literals - khwpypfs;
• ,J epiyahd nghUs; vdg;gLk;. mjhtJ> ,J nra;epuypy; khwhj;jd;ik cilajhff;
fhzg;gLk;.
A constant is a name that stores a value which should not change during program execution.
cjhuzk;:
PI = 3.14159
Reserved words
False, None, True, and, as, assert, async, await, break, class, continue, def, del, elif, else, except,
finally, for, from, global, if, import, in, is, lambda, nonlocal, not, or, pass, raise, return, try, while,
with, yield
To check the keyword list, type following commands in interpreter
import keyword
[Link]
2 of 87
nry;Ygbahd (valid) kw;Wk; nry;Ygbaw;w (invalid) khwpfSf;F cjhuzk; gpd;tUkhW>
1. Var = 10 ✔
2. my_var = 10 ✔
3. _my_var = 10 ✔
4. myVar = 10 ✔
5. MYVAR = “Raj” ✔
6. Myvar1 = “Raj” ✔
7. _1myvar = 10 ✔
1. 1Myvar = 10 ✘
2. my-var = 10 ✘
3. my var = 10 ✘
4. my#var = 10 ✘
5. _my$var=10 ✘
6. 5_var = 10 ✘
7. _#Comment = 10 ✘
3 of 87
13. print("It's Clear in 2026?") 15. print("It's my coding style")
6. print("Python\\tutorial")
7. print("Python\\\tutorial")
8. print("Python\\\\Class")
9. print("Python\\\\\Class")
11. print("Python\\nClass")
4 of 87
Python input() Function
• The input() function is used to take input from the user through the keyboard.
• When the program reaches input(), it waits for the user to type a value and press Enter.
The entered value is always treated as text (string) by default.
• It always returns a string. Use int() or float() to convert input for calculations
Basic Syntax
variable = input()
or
variable = input("Message to user")
Example:
Exercise:
1. msg = input("Message: ")
print("Your message is", msg)
5 of 87
8. length = float(input("Enter length: "))
width = float(input("Enter width: "))
area = length * width
print("Area =", area)
Python Comments
Programming languages are like conversations between humans and machines. The machine only cares
about instructions. Humans, however, need context. Comments are the little notes programmers leave for
each other and for their future selves, who will inevitably forget why something clever was written at 2 AM.
In Python, comments are pieces of text that the interpreter ignores. They are used to explain code,
describe logic, or temporarily disable parts of a program during testing.
nra;epunyhd;wpd; Fwpg;gpl;l $w;Wf;fspid tpgupg;gjw;fhf toq;fg;gLk; $w;Wf;fs;. vjpu;fhyj;jpy;
Fwpj;j nra;epunyhd;wpid Fwpj;j egu; my;yJ NtnwhUtu; mwpe;J nfhs;tjw;fhf toq;fg;gLk;.
FwpKiwfshdJ ntspaPl;by; vt;tpj khw;wj;jpidAk; Vw;gLj;jhJ. igjd; nra;epuyhf;fj;jpy;
gpd;tUkhW Fwpg;Giu toq;fg;gLk;.
Single-Line Comment (#)
# This is a comment
6 of 87
Python Casting - Type Conversion
• juTfis xU tifapy; ,Ue;J ,d;DnkhU tiff;F khw;Wtjw;fhf ,e;;j El;gk;
gad;gLj;jg;gLfpd;wJ.
1) x = int(312) 5) y = float(9.63) 9) x = float("45")
print(x) print(y) print(x)
11) q = float("760")
3) x = int(4.72) 7) p = float("Coding") print(q)
print(x) print(p) print(type(q))
Arithmetic Operators
Operators Name
+ $l;ly; (Addition)
- fopj;jy; (Subtraction)
* ngUf;fy; (Multiplication)
/ gpupj;jy; (Division)
% kPjp gpupg;ghd; (Modulus)
** mLf;F/ tY (Exponentiation/ power)
// Floor Division
7 of 87
1) x = 12 15) -7 * -8 30) 84 / 12.0
y = 38
x+y
16) 14 % 4 31) 24 % -7
2) 15 * 12
17) 6**3 32) -5**2
3) 7 * 3.5
18) -54 + 80 33) 85 - 120
4) 72.0 / 9.0
19) 7 * 14.0 34) 12.0 / 48
5) 72.0 / 9
20) 35 % 6 35) 24 % -5
6) 28 % -5
7) 28 % -6
22) 20 - 9 37) -3**7
8) a = 18
b = 7.0 23) 96 / 6 38) 6 // 3
a + b + 12
27) 81 / 9 42) 10 // 5
12) 9 % 4
8 of 87
Exercise : fPNo jug;gl;Ls;s igjd; vz;fzpj nraw;ghLfisj; jPu;f;f.
2) (3+8)//4*7-3/3 7) 5**3-(4%7)+3/5*8
3) 7%3/2+5**2-8//3 8) (4%11)+20-6/8*5//4**3*3
Assignment Operators
9 of 87
1) a = 15 9) a //= b
b=6 print(a)
a += 4
a += b
print(a) 10) x += y
z -= x
print(z)
2) x = 7
y = 12
z=5 11) b *= 8.0
x *= y print(b)
y *= x
print(z)
12) x //= z
x //= y
3) a %= b print(x)
print(a)
14) print(b)
6) print(x)
15) y += x
7) print(z) z *= 5
a /= 3 print(z)
b /= a
print(b, a)
16) print(x)
8) x %= 6
print(x + z)
10 of 87
Comparison Operators/ Relational Operators
,uz;L my;yJ mjw;F Nkw;gl;l $Wfis xg;gPL nra;J True my;yJ False Mfpa ,U
KbTfspy; VjhtJ xd;iwg; ngWtjw;fhf ,t; ,af;fp gad;gLj;jg;gLfpd;wJ.
,q;F $w;W cz;ik vdpd; True vDk; tpisTk;> $w;W ngha; vdpd; False vDk; tpisTk;
ngwg;gLk;.
1. Equal ==
2. not equal !=
3. Greater than >
4. Less than <
5. Greater than and equal >=
6. Less than and equal <=
Priority Order → ==, !=, >=, >, <=, <
1) 7 = 3 7) 6 != 4
2) 18 < 12 8) 25 != 19
5) 6 != 6 11) 12 > 12
Logical Operator
,J epge;jidf; $w;Wf;fis ,izg;gjw;fhf gad;gLj;jg;gLfpd;wJ.
Logical Operator gad;gLj;jg;gLk; NghJ True my;yJ False vDk; tpisT fpilf;Fk;.
1. NOT → ,q;F $w;W True vdpd; False vdTk;> $w;W False vdpd; True vdTk; tpist
fpilf;Fk;.
2. AND → ,q;F ,U $w;Wf;fSk; True fhzg;gbd; khj;jpuNk tpisT True MFk;.
3. OR → ,q;F VjhtJ xU $w;W True Mf fhzg;gbd; ntspaPL True Mf fpilf;Fk;.
Priority Order → NOT, AND, OR
11 of 87
1) 12 > 5 and 5 < 12 6) 8 < 12 and 15 > 10
Identity Operator
xU nghUs; epidtfj;jpy; Fwpg;gpl;l ,lj;jpid Rl;bf;fhl;Lfpd;wjh? vd;gij rupghu;g;gjw;fhf
gad;gLj;jg;gLfpd;wJ. ,q;F True my;yJ False Mfpa ,uz;L tpisTfs; ngwg;gLk;. ,jpy;
Operator Meaning
is Returns True if both variables refer to the same object
is not Returns True if both variables refer to different objects
a == b y is x
a is not b x == y
x is not y
12 of 87
3) a = "Programming" 4) a = 8
b = "Programming" b=8
a is b b is not a
b is a a is b
a == b a == b
a is not b c=a
a is c
c is a
c == a
a is not c
The Membership Operator in Python is used to check whether a value exists inside a sequence or
collection. The collection can be a list, tuple, string, set, or dictionary. Instead of comparing objects or
identities, membership operators ask a simpler question: Is this element contained within that structure?
Python provides two membership operators:
Operator Meaning
in Returns True if the value exists in the sequence
not in Returns True if the value does not exist in the sequence
13 of 87
5) team = ["IND", "AUS", "ENG", "SA"]
"IND" in team →
"PAK" in team →
"NZ" not in team →
"I" in team[0] →
"G" in team[2] →
"S" in team[3] →
"AUS" in team →
"U" in team[1] →
14 of 87
Bitwise Operators
bit njhlu;ghd ju;f;ftpay; ,af;fpfshf gpd;tUtd fhzg;gLfpd;wd. ,it bit fspd; kPJ
khj;jpuNk gpuNahfpf;fg;gLfpd;wd. bit njhlu;ghd ju;f;ftpay; ,af;fpfshf gpd;tUtd
gad;gLj;jg;gLfpd;wd.
` ` OR
^ XOR 5^3
~ NOT ~5
3) 10 | 7 13) 15 & 12
15 of 87
Standard Data types in python
• igjdpy; cs;s xt;nthU ngWkjpfSf;Fk; (value) juTtif (Data type) cs;sJ. igjd;
nra;epuypy; midj;Jk; nghUs; (object) vd;gjhy; juT tiffs; tFg;Gf;fshfTk;
(classes) khwpfshdJ mt; tFg;Gf;fspd; nghUs; MfTk; fhzg;gLk;.
Every value in Python has a datatype. Since everything is an object in Python programming, data
types are actually classes and variables are instance (object) of these classes.
1. Numbers
• Integral → Whole-number types.
o Integer → Stores positive or negative whole numbers without decimals.
o Boolean → Stores only two values: True or False.
• Real → Usually refers to floating-point numbers (float), which contain decimal values.
• Complex → Stores complex numbers with a real and imaginary part. Imaginary part is
16 of 87
Python Numbers
Note2 → To verify the type of any object in python, use the type( ) function
(VjhtJ nghUspw;fhd juT tifia ghu;g;gjw;F type( ) vDk; function gad;gLj;jg;gLk;)
17 of 87
name = "Hello world" x = "Python Programming"
x = "Welcome"
1. print(name) 1. print(x[0])
2. print(x) 2. print(x[1:5])
3. print("name") 3. print(x[0:6])
4. print(name[1]) 4. print(x[11:12])
7. print(name + x) 7. print(x[-1:-4])
18 of 87
x = "Software Engineering" val = "Networking"
1. print(x[1:5]) 1. print(val[-1:-10])
2. print(x[5:12])
2. print(val[-1:-10:-1])
3. print(x[1:])
3. print(val[-1:-11:-1])
4. print(x[5:])
4. print(val[-1:-15:-1])
5. print(x[:8])
6. print(x[:10]) 5. print(val[-1:-11:-2])
7. print(x[:])
6. print(val[:-8:-1])
8. print(x[0:10:1])
7. print(val[-4::-1])
9. print(x[:10:2])
12. print(x[::2])
10. print(val[-5::-1])
13. print(x[:14])
11. print(val[:-4:-2])
14. print(x[::3])
12. print(len(val))
15. print(x[::2])
17. print(x[:10:1])
14. print([Link]())
18. print(x[1:1])
15. print([Link]())
19. print(x[1:1:1])
20. print(x[:10:])
21. print(x[:5:2])
22. print(x[12:16:3])
19 of 87
x = "Sathith Python Tutorial"
20 of 87
LIST (gl;bay;)
• xU jdp khwpapDs; gy ngWkjpfis Nrkpg;gjw;fhf ,J gad;gLj;jg;gLk;.
• mjhtJ> gy;NtWgl;l juTtiffis cs;slf;fpa (int, float, str, tuple) xU njhFjpahd
juTtif ,JthFk;.
• ,J igjd; nra;epuypy; [ ] milg;gpDs; vOjg;gLtNjhL mtw;wpy; cs;slf;fg;gLk;
ngWkhdk; comma ( , ) %yk; NtWgLj;jg;gLk;.
• ,it tupir Kiwapy; mike;jpUf;Fk; ngWkhdj;ij cs;slf;Fk; (Ordered)
• igjdpy; LIST I cUthf;fpa gpd;du; mjpy; khw;wq;fis Vw;gLj;jyhk; (changeable)
Note1: List Items are ordered → it means that the item have a defined order, and that order will not change.
If you add new items to a list, the new item will be placed at the end of the list.
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
Note2: List Items are changeable → it means that we can update, add and remove items in a list after it
Note4: List items are indexed → the first item has index [0], the second item has index [1] etc.
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
21 of 87
Question 01: Question 02:
data = ["Book", "Pen", 25, "Car", 42, "Laptop"] nums = [7, 12, 3, 9, 15]
print(data) print(nums)
print(data[4]) print(nums * 3)
print(data[2],[3]) print(nums)
print(data[-5]) print(nums[2:6])
print(data[1:2]) print(len(nums))
print(data[:5]) y = 12
print(data[4::-1])
print(data[1::-1])
22 of 87
Question 03: Question 04:
print([3,7,1] + [9,2,5]) items = ["Python", 12, [5, 9, 3], 7, "Code"]
print([6] * 3) print(len(items))
print([12,5,7] * 2) print(len(items[2]))
print(type([3,9,4,"Text",15])) print(len(items[0]))
print([9,2,4][1] * 5) print(items2)
print(["code",5,8,"Python"][3][1] * 3) print(type(items2))
print(items + ["Data"])
23 of 87
Question 05: Index Method. Questions 07: Python List Extend()
letters = ["P", "Q", "R", "S", "T"] The extend() method adds all the elements of an
iterable (list, tuple, string etc.) to the end of the
list.
index = [Link]("P")
[Link](subB)
print([Link]("T"))
print(subA)
values = [3,6,9,12,'9',15,9,'15']
print(subB)
print([Link](9))
[Link]('geo')
print([Link]('9'))
flavorB = ['Apple']
print([Link]('15'))
[Link](flavorB)
Question 06: The append() method adds an
item to the end of the list
print(flavorA)
snacks = ["Burger", "Pizza", "Sandwich"]
languages = ['Spanish']
[Link]("Pasta")
lang_tuple = ('German', 'Italian')
print(snacks)
lang_set = {'Arabic'}
# Adding list to a list
[Link](lang_tuple)
new_snacks = ["Noodles", "Fries"]
print("New Language List is:", languages)
[Link](new_snacks)
[Link](lang_set)
print(snacks)
print("New Language List is:", languages)
24 of 87
x = [12,18]
y = [25,35]
z = (3,4)
[Link](z)
print(z)
[Link](z)
print(y)
25 of 87
# Python List pop()
# The pop() method removes the item at the given index from the list and returns the removed
item.
Note →
1. The pop() method takes a single argument (index).
2. The argument passed to the method is optional. If not passed, the default index -1 is passed
as an argument (index of the last item).
3. If the index passed to the method is not in range, it throws IndexError: pop index out of
range exception.
print(‘When -1 is passed’) →
rem = [Link](-1)
print(course) →
print(‘When -6 is passed’) →
print(‘Return value:’, [Link](-6)) →
print(‘New course:’, course) →
26 of 87
# Python List sort()
# The sort() method sorts the elements of a given list in a specific ascending or descending order.
list1 = [18,10,15,’Hello’]
list2 = list1
print(list2) →
[Link](‘Python’)
Note: The problem with copying lists in this way is that if you modify list2, list1 is also modified. It
is because the new list is referencing or pointing to the same list1 object.
Note2: However, if you need the original list unchanged when the new list is modified, you can use
the copy() method.
old = [4,5,6,8]
new = [Link]()
print(‘Copied list:’, new) →
[Link](10)
print(new) →
old_list = [4,6,8,10,12]
new_list = old_list[:]
print(new_list) →
new_list.append(14)
print(‘Old list is:’, old_list) →
print(‘New list is:’, new_list) →
x = [5,10,48,42]
[Link]()
print(x) →
27 of 87
# Emptying the List Using del
x = [10,12,16]
del x[:]
print(x) →
x = [5,4,6,8]
del x
print(x)
Creating a Tuple
variable_name = (val1, val2, val3, Valn)
print(subjects) →
print(len(subjects)) →
print(type(subjects)) →
tuple1 = ('Java',)
print(type(tuple1)) →
tuple2 = ('Java')
print(type(tuple2)) →
tuple3 = (25)
print(type(tuple3)) →
tuple4 = (12.8)
28 of 87
print(type(tuple4)) →
tuple5 = (7,14)
print(type(tuple5)) →
tuple6 = ([8,3])
print(type(tuple6)) →
print(type(7)) →
# Note: To create a tuple with only one item, you must add a comma.
print(x) →
print(new) →
print(type(new)) →
y = tuple([5, 9, 'Python'])
29 of 87
a = (10,12,5,6,7,8,10,22,10)
print(a[0:]) →
print(a[0::2]) →
print(a[::-1]) →
print(a[-1::-3]) →
print(a[1:10:3]) →
Note → Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable
as it also is called. But there is a workaround. You can convert the tuple into a list, change the list,
30 of 87
fruit = ("Apple", "Mango", "Apple", "Grapes")
[Link](‘Grapes’)
print(fruit) →
Note → You cannot remove items in a tuple. Because Tuple is an immutable Datatype.
Note → You can delete the tuple completely
Unpack Tuple
>>> print(T) →
The values ‘red’, ‘green’, ‘blue’ and ‘cyan’ are packed together in a tuple.
>>> (a,b,c,d) = T →
>>> print(a) →
>>> print(b) →
>>> print(c) →
>>> print(d) →
31 of 87
Question
Answer → ?
32 of 87
Set (njhil)
• xU jdp khwpapy; gy ngWkjpfis Nrkpg;gjw;fhf ,J gad;gLj;jg;gLfpd;wJ.
• ,J igjdpy; { } ,Ds; vOjg;gLtNjhL> ,jpYs;s xt;nthU ngWkjpfSk; comma (,) ,dhy;
NtWgLj;jg;gl;bUf;Fk;.
• A Tuple is a collection which is unordered and unindexed.
• Sets are unchangeable → Sets are unchangeable, meaning that we cannot change the items after the set
has been created. Once a set is created, you cannot change its items, but you can add new items.
• Duplicated not allowed – Sets cannot have two items with the same value.
Python set is an unordered collection of unique items. They are commonly used for computing mathematical
operations such as union, intersection, difference, and symmetric difference.
33 of 87
>>> x = {‘ICT’, ‘BST’, ‘ET’, ‘SFT’}
>>> [Link](‘Agri’) # Add items
>>> print(‘New Tuple x is:’,x) →
>>> print(len(x)) →
>>> brand = {‘Asus’, ‘Acer’, ‘Apple’, ‘Dell’}
>>> brand2 = {‘Hp’, ‘IBM’, ‘Singer’, ‘Huawei’}
>>> [Link](brand2)
>>> print(brand) →
>>> print(brand2) →
# The object in the update() method does not have be a set, it can be any iterable object (tuples,
lists, dictionaries etc).
>>> num1 = {4,6,8,7}
>>> num2 = [10,12,16,18]
>>> [Link](num2)
34 of 87
# You can also use the pop(), method to remove an item, but this method will remove the last item.
Remember that sets are unordered, so you will not know what item that gets removed.
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
# Sets are unordered, so when using the pop() method, you do not know which item that gets removed.
……………………………………………………………………………………………………………
……………………………………………………………………………………………………………
35 of 87
# The intersection_update() method will keep only the items that are present in both sets.
# The intersection() method will return a new set, that only contains the items that are present in both sets.
# The symmetric_difference_update() method will keep only the elements that are NOT present in both
sets.
# The symmetric_difference() method will return a new set, that contains only the elements that are NOT
present in both sets.
36 of 87
Set Operations
• Sets are commonly used for computing mathematical operations such as intersection, union,
difference, and symmetric difference.
Set Union
• You can perform union on two or more sets using union() method or | operator.
Set Intersection
• You can perform intersection on two or more sets using intersection() method or & operator.
37 of 87
Set Difference
• You can compute the difference between two or more sets using difference() method or -
operator.
38 of 87
Dictionary (mfuhjp)
• Dictionaries are used to store data values in key : value pairs.
……………………………………………………………………………………………………
• An item has a key and a corresponding value that is expressed as a pair (key: value).
……………………………………………………………………………………………………
• A dictionary is a collection which is unordered, changeable and does not allow duplicates.
………………………………………………………………………………………………………
…………………………………………………………………………………………………
• Dictionaries are written with curly brackets - { }, and have keys and values.
……………………………………………………………………………………………………
• While the values can be of any data type and can repeat, keys must be of immutable type (string,
number or tuple with immutable elements) and must be unique.
………………………………………………………………………………………………………
…………………………………………………………………………………………………
……………………………………………………………………………………………………
……………………………………………………………………………………………………
>>> meals = {'veg':'dhal', 'non-veg':'chicken', 'fruit':'mango', 'drink':'milk'} "Sparking minds, The best education"– [Link]
>>> print(meals)
>>> print(len(meals))
>>> print(type(meals))
>>> print(meals['veg'])
>>> print(meals['non-veg'])
>>> print(meals['dhal'])
39 of 87
>>> new_dict = {'Name': 'Sathith', 'Year': 1999, 'M,D': ['Jun', 21]}
>>> print(new_dict)
>>> print(len(new_dict))
>>> print(type(new_dict))
>>> print(new_dict['Name'])
>>> print(new_dict['M,D'])
we can also create a dictionary using the built-in dict() function.
>>> dict_2 = dict({1:'one', 2:'two', 3:'three', 4:'four', 5:'five'})
>>> print(dict_2)
>>> print(dict_2[1])
Accessing Items
You can access the items of a dictionary by referring to its key name, inside square brackets:
There is also a method called get() that will give you the same result
>>> new_dict = {'Name': 'Sathith', 'Year': 1999, 'M,D': ['Jun', 21]}
>>> print(new_dict.get(‘Name’))
>>> year = new_dict.get(‘Year’)
>>> print(year)
Note →
If we use the square brackets [ ], KeyError is raised in case a key is not found in the dictionary. On the
other hand, the get() method returns None if the key is not found.
>>> city = {'Eastern':'Trincomalee', 'Northern':'Jaffna', 'Western':'Colombo'}
>>> print(city['Northern'])
>>> print([Link]('Western'))
>>> print(city['Southern'])
>>> print([Link]('Southern'))
40 of 87
>>> x = {'Name': 'Sathith', 'Year': 1999, 'M,D': ['Jun', 21]}
>>> [Link]( ) →
>>> x['Name']='Sathithraj'
>>> print(x) →
>>> y = [Link]() →
>>> print(y) →
Note→ The returned list is a view of the items of the dictionary, meaning that any changes done to
the dictionary will be reflected in the items list.
Update Dictionary
The update() method will update the dictionary with the items from the given argument. The argument
must be a dictionary, or an iterable object with key:value pairs.
>>> meals = {'veg':'dhal', 'non-veg':'chicken', 'fruit':'mango', 'drink':'milk'}
>>> [Link]({‘fruit’ : ’grapes’})
>>> print(meals)
41 of 87
Note → The update() method will update the dictionary with the items from a given argument. If the
item does not exist, the item will be added.
>>> [Link]({‘May’:5})
>>> print(month) →
Note → The pop() method removes the item with the specified key name
Note → The popitem() method removes the last inserted item (in versions before 3.7, a random item is
removed instead)
>>> [Link]()
>>> print(month) →
Note → The del keyword removes the item with the specified key name
>>> del month[‘Mar’]
>>> print(month) →
42 of 87
Empties the Dictionary
>>> month = {'Jan':1, 'Feb':2, 'Mar':3}
>>> print(month) →
>>> [Link]()
>>> print(month) →
>>> print(month) →
>>> print(month) →
>>> print(monthcopy) →
>>> print(monthcopy2) →
43 of 87
nra;epuy; tpUj;jpapy; fl;Lg;ghl;Lf; fl;likg;Gf;fisg; gad;gLj;Jthu;
nra;epuy; fl;Lg;ghnlhd;wp gha;r;ryhdJ %d;W mbg;gilf; fl;Lg;ghl;Lf; fl;likg;Gf;fisf;
nfhz;L nraw;gLj;jg;gLk;.
1. njhlu; (Sequence)
2. njupT (Selection)
• if
• if-else
• if-elif-else
44 of 87
if fl;lisf;fhd gha;r;rw; Nfhl;Lg;glk; :
xU vz; cs;sPL nra;ag;gLk; NghJ mJ xw;iw vz;zh? my;yJ ,ul;il vz;zh? vdf;
fhz;gjw;Fj; Njitahd igjd; FwpKiwapid vOJf.
45 of 87
Python if…elif…else statement
OR
46 of 87
Question 01
a=7
b=3
if a > b:
print(a + b)
print(a - b)
Question 02
marks = 75
if marks >= 50:
print("Pass")
else:
print("Fail")
print("Result Released")
x = 15
if x % 3 == 0:
print("Divisible by 3")
else:
print("Not divisible by 3")
if x % 5 == 0:
print("Divisible by 5")
Question 04
x = 20
y = 10
if x > 15:
if y > 5:
print("P")
print("Q")
print("R")
47 of 87
Question 05
a=8
b = 12
if a > 5:
if b < 10:
print("X")
else:
print("Y")
else:
print("Z")
Question 06
x=6
y=9
Question 07
x=5
y = 15
z = 10
if x < y:
print("A")
if y < z:
print("B")
else:
print("C")
if z > x:
print("D")
else:
print("E")
print("F")
48 of 87
Question 08
x=5
y = 15
z=5
if x == z:
print("P")
if y > x:
print("Q")
if y % x == 0:
print("R")
else:
print("S")
else:
print("T")
else:
print("U")
Question 09
a=9
b=4
c = 12
if a > 5:
print("X")
if b % 2 == 0:
print("Y")
if c < 10:
print("Z")
else:
print("W")
if a + b == c:
print("T")
else:
print("U")
else:
print("V")
else:
print("N")
print("END")
49 of 87
Repetition
• Python ,y; 02 tifahd looping fl;lisfs; gad;gLj;jg;gLfpd;wd.
1. while loops
2. for loops
The while Loop
• ,U epge;jid cz;ikahf ,Uf;Fk; tiu rpy nraw;ghLfis Nkw;nfhs;tjw;F ,J
gad;gLj;jg;gLfpd;wJ.
Flow Chart
Syntax
i = 0 (Starting value)
50 of 87
i=1 i=1 i=1
while (i<15): while (i<10): while (i<10):
print('No',i) print(i*i) print(i*i, end="")
i=i+5 i+=1 i+=1
print('No+No =',i+i)
51 of 87
x=1 x=1 x=1
y = 10 while(x<6): while(x<6):
while(x<5): print("Sathith") print(("raj"*x)," @")
y = y*x x=x+1 x=x+1
x=x+1
y=y-2
print("x = ",x)
print("y = ",y)
print(x+y)
x=1 x = 10 x=1
y=1
while x <= 3: while x > 0:
y=1 print(x // 3) while x <= 3:
while y <= 2: x -= 3 while y <= 3:
print(x, y) print(x + y)
y += 1 y += 1
52 of 87
The For Loop
for VAL in range (Start value, end value, Step by)
Questions
for i in range(10): for i in range(0,10): for i in range(0,10):
print(i) print(i) print(i,end='')
53 of 87
for x in range(10,15,2): for x in range(10,15,2): Total=0
Sum=0 Sum=Sum+x for x in range(1,15,2):
Sum=Sum+x x=x+2 Total=Total+1
x=x+2 print(Sum) x=x+5
print(Sum) print(x) print(x)
print(x) print(Total)
54 of 87
num = [1,2,3,4,5] vowels = ['a','e','i','o','u'] vowels = ['a','e','i','o','u']
ltr = ['A','B','C','D','E'] for vow in range (len(vowels)): for vow in range (len(vowels)):
for x in ltr: print(vow) print(vowels[vow])
[Link](x)
print(num)
55 of 87
Questions →
fPNo jug;gl;Ls;s ntspaPl;bidg; ngWtjw;Fj; Njitahd igjd; FwpKiwf; $w;wpid vOJf.
output code
56 of 87
The pass Statement
• In Python programming, the pass statement is a null statement. t is used as a placeholder for future
implementation of functions, loops, etc.
Example →
x=1
i=1 i = 10 i = 10
while i < 7: while i > 1: while i > 1:
if i == 3: i-=1 i-=1
break if i == 5: if i == 5:
i += 1 break break
print(i, end=‘,’) print(i) i -= 1
print(i, end=“ ”)
Answer → Answer →
Answer →
57 of 87
count = 0 count = 0 count = 1
while 1: while True: while True:
print(count) count += 1 count += 1
count += 1 print(count) if count >= 5:
if count >= 5: if count >= 5: break
break break print(count)
Example →
defining a function
def fun1( ):
print("Python by Sathith")
Calling a function →
• To call a function, use the function name followed by parenthesis:
def fun1( ):
print("Python by Sathith")
calling a function
fun1( )
58 of 87
def calc():
num1 = int(input("Enter a number: "))
num2 = int(input("Enter a number: "))
add = num1+num2
sub = num1-num2
mul = num1*num2
div = num1/num2
print('Sum',add)
print('Subtract',sub)
print('Multiplication',mul)
print('Division',div)
calc()
mulBy10(7.5) func1('Eastern')
Example 3 → Example 4 →
calc(5,10)
59 of 87
Use a default parameter value
Example 1 → Example 2 →
newFun(2,10) newFun(2,10,12)
Example 3 → Example 4 →
newFun(2) newFun(2,4,10,12)
Example 5 → Example 6 →
printName() printName('Sathithraj')
x = 10 x = 10
def fun(): def fun():
x=30 x=30
print('Value inside the function:',x) print('Value inside the function:',x)
60 of 87
def new(x,y,z=10): def new(x,y,z=10):
print(x*y,z) print(x*y,z)
a=10 new(10,12)
b=5
new(a,b)
Note→
cal() print(cal())
61 of 87
def returnFun(): def returnFun():
x=4 x=6
return(x) return x
print(returnFun()) print(returnFun())
x = 10 def key():
def returnFun(): x=5
x=6 return 5*x
return x
return x return x
print(returnFun()) print(key())
Note →
print(loopFun()) loopFun()
print(loopWhile()) print(loopWhile())
62 of 87
def loopWhile(x=5): def loopWhile(x=5):
while(x>=1): while(x>=1):
print x return x
x-=1 x-=1
print(loopWhile()) print(loopWhile())
print return
63 of 87
Python Global, Local and Nonlocal Variables
(G+Nfhs khwp> cs;sik khwp kw;Wk; cs;sik my;yhj khwp)
Global Variable (G+Nfhs khwp)
• In Python, a variable declared outside of the function or in global scope is known as a global variable.
This means that a global variable can be accessed inside or outside of the function.
Example →
x = 5 # Global Variable
def globalVar():
print('x inside:',x)
globalVar()
print('x outside:',x)
output →
Example 2 →
x = 5 # Global Variable
def globalVar():
x = x + 10
globalVar()
x = 5 # Global Variable
def globalVar():
global x
x = x + 10
print(x)
globalVar()
64 of 87
Question →
x=5 x=5 x=5
def globalVar(): def globalVar(): def globalVar():
global x global x global x
x = x + 10 x = x + 10 x = x + 10
print(x) print(x) print(x)
print(localVar()) print(localVar())
print(x)
65 of 87
x = 'global' x = 'global' x = 'global'
def outer(): def outer(): def outer():
x = "local" x = "local" x = "local"
In Python, we know that a function can call other functions. It is even possible for the function to
call itself. These types of construct are termed as recursive functions.
66 of 87
Example 1 →
def factorial(x):
if x == 1:
return 1
else:
return (x * factorial(x-1))
num = 5
print("The factorial of", num, "is", factorial(num))
output →
Example 2 →
def fun(n):
if n == 0:
return 0
Example output
67 of 87
Questions:
68 of 87
Python File Handling
• igjdpy; Nfhg;Gf;fis ifahSk; NghJ open( ) vDk; function Kjd;ikahf fhzg;gLk;.
(The key function for working with files in Python is the open() function.)
• Files are named locations on disk to store related information. They are used to permanently store
data in a non-volatile memory (e.g. hard disk).
• Since Random Access Memory (RAM) is volatile (which loses its data when the computer is
turned off), we use files for future use of the data by permanently storing them.
• When we want to read from or write to a file, we need to open it first. When we are done, it needs
to be closed so that the resources that are tied with the file are freed.
Read a File
[Link] ↓
code → output →
f = open("[Link]","r")
print([Link]())
69 of 87
Open a file on different location
f = open("D:\\[Link]","r")
print([Link]())
code → output →
f = open("[Link]","r")
Read Lines
Example 1 →
f = open("[Link]","r") →
print([Link]())
f = open("[Link]","r") →
print([Link]())
print([Link]())
Example 2 →
f = open("[Link]","r")
for x in f:
print(x)
70 of 87
Close Files
Example →
f = open("[Link]","r")
print([Link]())
[Link]()
Python File Write
1. Write Mode
Example 1 →
f = open("[Link]","w")
[Link]("Python Write Mode in File Handling")
Example 2 →
f = open("[Link]","w")
[Link]("Python Write Mode in File Handling")
[Link]()
2. Append Mode
Example →
f = open("[Link]","a")
[Link]("\nHi there!")
[Link]()
71 of 87
Note 1 → The "w" method will overwrite the entire file.
Delete a File
• To delete a file, you must import the OS module, and run its [Link]() function
• Example →
import os
[Link]("[Link]")
import os
if [Link]("[Link]"):
[Link]("[Link]")
else:
print("The file does not exist")
Delete Folder
import os
[Link]("New folder")
72 of 87
Nju;r;rp kl;lk;: 9.12
juTj;jsq;fspy; juT Kfhikj;Jtk; nra;thu;.
igjd; MySQL
juTj;jsg; gpuNahfq;fspy; igj;jd; nkhopiag; gad;gLj;jKbAk;. MySQL MdJ gpugy;akhd
juTj;js nkd;nghUs;fspy; xd;whFk;.
MySQL nrYj;jpapid epWTjy;
igj;jd; nkhopf;F MySQL juTj;jsj;jpid mZFtjw;F MySQL nrYj;jp mtrpakhFk;.
,jw;fhf "MySQL Connector" vd;w nrYj;jp gad;gLj;jg;gLfpd;wJ. "MySQL Connector" ,id
epWTtjw;F PIP gad;gLj;jg;gLfpd;wJ. igj;jd; nghjpfs; my;yJ modules ,w;F PIP xU nghjp
Kfhikahsu; MFk;. igj;jd; epWtg;gLk; NghNj PIP vd;gJk; mNdfkhf epWtg;gl;bUf;Fk;.
(igj;jid epWTk; NghJ, “Install Now” ,w;Fg; gjpyhf “Customize installation” vd;gijj; njupT
nra;jy; Ntz;Lk;. ,t;thwhd epiyapy; PIP jhdhfNt epWtg;gLk;.)
igj;jd; epWtg;gl;Ls;s miltpidf; fl;lis tupA+lhf mZfpg; gpd;tUk; fl;lisapid
toq;FtjD}lhf PIP epWtg;gl;Ls;sjh vd;gijg; guPl;rpf;fyhk;.
C:\Users\your name\AppData\Local\Programs\Python\Python37-32\Scripts> pip – version
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password =""
)
print(dbConnect)
73 of 87
juTj;jsnkhd;wpid cUthf;Fjy;
KV vDk; ngaupy; juTj;jsnkhd;wpid cUthf;Fjy;
juTj;jsnkhd;wpid ePf;Fjy;
KV vDk; ngaiuAila juTj;jsj;jpid ePf;Fjy;
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
[Link]("CREATE TABLE staffga(staffId int, name varchar(255) not null, address
varchar(255), dob date, stafftype varchar(100), primary key(staffId))");
74 of 87
ml;ltiziaj; jpUj;jpaikj;jy; (Modify)
Staff ml;ltizapDs; Salary vDk; Gjpa Gyj;jpid Nru;j;jy;
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
[Link]("ALTER TABLE staff ADD Salary float");
ml;ltizapid ePf;Fjy;
Staff vDk; ngaUila ml;ltizapid ePf;Fjy;
mycursor = [Link]()
[Link]("DROP TABLE staff");
75 of 87
ml;ltiznahd;wpDs; juTfis cs;Eioj;jy;
,jw;fhf commit( ) Kiw mtrpakhFk;. ,y;iynadpy; ml;ltizapy; khw;wq;fs; Vw;gLj;jg;gl
khl;lhJ.
staff ml;ltizf;F Gjpa gjptpid cl;Nru;j;jy;
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
sql = "INSERT INTO staff (staffId, name, address, dob, stafftype, Salary) VALUES
(%s,%s,%s,%s,%s,%s)"
val = ("1001","Sathith","Thirukkovil","1999-06-21","Academic","128000")
[Link](sql,val);
mycursor = [Link]()
sql = "INSERT INTO staff (staffId, name, address, dob, stafftype, Salary) VALUES
(%s,%s,%s,%s,%s,%s)"
val = [
("1002","Diloo","Akkaraipattu","1997-12-10","Academic","130000"),
("1003","Raj","Colombo","1994-4-18","Academic","96000")
]
[Link](sql,val);
[Link]()
print([Link], "record inserted")
76 of 87
juTfisj; njupT nra;jy;
ml;ltizapy; ,Ue;J midj;Jj; juTfisAk; ngWtjw;F fetchall( ) Kiw gad;gLj;jg;gLk;.
fetchone( ) Kiwiag; gad;gLj;jp xU gjptpid khj;jpuk; ngwyhk;.
Staff table structure
mycursor = [Link]()
[Link]("SELECT * FROM staff")
result = [Link]()
for i in result:
print(i)
Output:
77 of 87
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
[Link]("SELECT * FROM staff WHERE stafftype = 'academic'")
result = [Link]()
for i in result:
print(i)
Output:
mycursor = [Link]()
[Link]("SELECT * FROM staff")
result = [Link]()
print(result)
Output →
78 of 87
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
[Link]("SELECT * FROM staff")
result = [Link]()
for x in result:
print(x)
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
[Link]("SELECT name, address FROM staff")
result = [Link]()
for x in result:
print(x)
Output →
79 of 87
ml;ltizapYs;s juTfis ,w;iwg;gLj;jy;
Staff ml;ltizapYs;s 1004 vDk; Staff Id ,id cila Copaupd; Kftupia Kalmunai Mf
khw;wk; nra;jy;.
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
sql = "UPDATE staff SET address = 'Kalmunai' WHERE staffId='1004'"
[Link](sql)
[Link]()
print([Link], "record(s) affected")
import [Link]
dbConnect = [Link](
host = "localhost",
user = "root",
password ="",
database = "kv"
)
mycursor = [Link]()
sql = "DELETE FROM staff WHERE staffId='1003'"
[Link](sql)
[Link]()
print([Link], "record(s) affected")
80 of 87
Nju;r;rp kl;lk;: 9.13 NjLjYk; tupirg;gLj;jYk; (Searches and sorts data)
Njly; El;gq;fs;
Fwpj;j cUg;gbfspd; njhFjpapy; ,Ue;J Fwpj;j xU cUg;gbapidj; NjLtjw;Fg;
gad;gLj;jg;gLk; newpKiwr; nrad;Kiw Njly; vdg;gLk;. toikahfj; NjlyhdJ True my;yJ
False vd;gijj; NjlYf;fhd gjpyhfj; jUk;.
igj;jd; nkhopapy; Fwpj;j cUg;gbahdJ gl;baYf;Fs; cs;sjh vd;gijg; gupNrhjpg;gJ
,yFthdjhFk;. ,jw;F "in " vd;Dk; nrayp gad;gLj;jg;gLfpd;wJ.
njhlupay; Njly;
▪ gl;bay; Nghd;w njhFg;Gfspy; Nrkpf;fg;gl;Ls;s juT cUg;gbfs; njhlu;r;rpahd my;yJ
tupirg;gLj;jy; El;gq;fs;
tupirg;gLj;jy; vd;gJ juTfis xU Fwpj;j xOq;fpy; tbtikg;gjhFk;. mt;nthOq;fikg;G
VWtupir my;yJ ,wq;Ftupirahff; fhzg;glyhk;.
tupirg;gLj;jy; newpKiwahdJ> juTfis xU Fwpj;j tupirapy; xOq;F gLj;Jk; Kiwiaf;
Fwpg;gpLfpd;wJ.
Fkpo; tupirg;gLj;jy; (Bubble Sort)
Fkpo; tupirg;gLj;jyhdJ> gl;baypD}lhfg; gy flj;jy;fis (passes) Nkw;nfhs;fpd;wJ. ,q;F
mLj;Js;s cUg;gbfs; xg;gplg;gl;L mit xOq;fw;Wf; fhzg;gLkhapd; ,lk;khw;wg;gLk;.
gl;baypd; xt;nthU flj;jypd; NghJk; mLj;j ngupa ngWkhdk; cupa ,lj;jpy;
epiyg;gLj;jg;gLk;. RUf;fkhff; $wpd; xt;nthU cUg;gbAk; mjw;Fupa ,lj;jpy;
epiyg;gLj;jg;gLk; (bubbles up).
81 of 87
gl;bay; xd;wpid VWtupirg;gLj;jy;
▪ KjyhtJ kw;Wk; ,uz;lhtJ epiyfspy; fhzg;gLk; $Wfis xg;gply;.
▪ KjyhtJ epiyapy; fhzg;gLk; ngWkhdk; ,uz;lhtJ epiyapy; fhzg;gLk;
ngWkhdj;jpid tplg; ngupjhapd; mtw;wpd; epiyfis khw;wy;.
▪ jw;NghJ ,uz;lhk; epiyapy; fhzg;gLk; ngWkhdk; Kd;whk; epiyapy; fhz;gLk;
ngWkhdj;Jld; xg;gplg;gl;L mtrpakhapd; epiy khw;wy;.
▪ ,t;thNw ,Wjp ,uz;L $Wfis xg;gpLk; tiu njhlu;e;J nra;jy;.
▪ jw;NghJ kpfg;ngupa $W mzpapd; ,Wjp epiyapy; fhzg;gLk;.
▪ ,t;thW> NkYk; epiykhw;wy;fs; Njit ,y;iynadf; fUJk; tiuf;Fk; ,r;nraiy
kPz;Lk; kPz;Lk; Muk;gj;jpy; ,Ue;J nraw;gLj;jy;. (cjhuzk;: gl;banyhd;iw
tupirg;gLj;jy;)
▪ mzpapDhlhf xt;nthU Kiw gazpf;Fk;NghJk; kpfg;ngupa $W ePu; Fkpop Nghy; mzpapd;
,Wjpf;Fr; nry;Yk;.
def bubble_sort(L):
swapped = True # set flag to True to repeat sorting
while swapped:
swapped = False
for i in range(len(L) – 1):
if L[i] > L[i + 1]:
# Swap the elements
L[i], L[i + 1] = L[i + 1], L[i]
# Set the flag to True so we’ll loop again
swapped = True
82 of 87
nra;epuy; nkhop ngau;g;gfq;fs; (Program Translators)
VjhtJ fzpdp epfo;rp epuy; nkhopapid gad;gLj;jp vOjg;gl;l %yr; nra;epuiy (source
program) > nghUs; Nehf;Fila (object) ,ae;jpu nkhopf;F khw;wg;glNtz;ba gzpapid ,J
Nkw;nfhs;fpd;wJ.
%yr; nra;epuy;/ %y fl;lisj; njhFjp (Source Program)
Python, Java, C, C++, C# Nghd;w cau;kl;l nkhopfspy; vOjg;gl;l nra;epuy;fs; MFk;. ,J
Fwpj;j nkhop gw;wpa mwpTs;s kdpju;fshy; tpsq;fpf; nfhs;sf;$bajhf cs;sJ.
A source program is a text file that contains instructions written in a high level language. It can not be
executed (made to run) by a processor without some additional steps. A source program is also called a
source file, source code, or sometimes, just source.
nghUs; Nehf;Fr; nra;epuy;/ cU fl;lisj; njhFjp (Object Program)
%yr; nra;epuy;fshdJ fzpdpapdhy; Neubahf tpsq;fpf; nfhs;sf; $ba 0, 1 ,id
mbg;gilahff; nfhz;l ,ae;jpu nkhopahf (machine code) khw;wg;gl;lJk; gpd;du; mit nghUs;
Nehf;Fr; nra;epuy; vd miof;fg;gLfpd;wd.
83 of 87
njhFg;gpfs; (Compilers)
njhFg;gpfs; %ynray;epuiy xNu jlitapy; nghUs; Nehf;F nray;epuYf;F khw;Wk;. ,r;nray;
Kiwapd; gpd; xU epue;ju Jtpj FwpKiwahf nghUs; Nehf;F nray;epuy; cUthf;fg;gLfpd;wJ.;
,jd; nraw;gL Neuk; FiwthdjhFk;.
njhFg;gpapidg; gad;gLj;Jk; nra;epuy; nkhopfs;: Pascal, C, C++, Java
Interpreter Vs Compiler
Interpreter Compiler
Translates program one statement at a time. Scans the entire program and translates it as a
whole into machine code.
Interpreters usually take less amount of time to Compilers usually take a large amount of time to
analyze the source code. However, the overall analyze the source code. However, the overall
execution time is comparatively slower than execution time is comparatively faster than
compilers. interpreters.
No Object Code is generated, hence are memory Generates Object Code which further requires
efficient. linking, hence requires more memory.
84 of 87
,uz;lhk; re;jjp fzpdp nkhop/ Assembly Language – 2GL
0,1 ,w;F gjpyhf vspa FwpaPLfs; gad;gLj;jp FwpKiw vOjg;gLk;. nra;epuy; epiwNtw;Wif
Ntfk; FiwT fhuzk; Translator gad;gLj;jg;gLk; (Assembler). 3GL kw;Wk; 4GL cld; xg;gpLk;
NghJ nra;epuy; vOJjy; kw;Wk; Nrhjid nra;jy; kpfTk; fbdk;. Fwpj;j fzpdpapy; /
,ae;jpuj;jpy; jq;fpapUf;Fk; nkhopahFk;. mjhtJ xU fzpdpf;F vOjpa nra;epuy; NtW
fzpdpf;F nghUe;jhJ. (Machine dependent)
%d;whk; jiyKiwf; fzpdp nkhop 3GL
nra;epuy;fs; ahTk; fzpj FwpaPLfs; ,aw;if nkhopapid gad;gLj;jp vOjg;gLk;. kdpjd;
tpsq;fpf; nfhs;tJ ,yF. nra;epuy; epiwNtw;Wif Ntfk; FiwT fhuzk; Translator mtrpak;.
1GL kw;Wk; 2GL cld; xg;gpLk; NghJ nra;epuy; vOJjy; kw;Wk; Nrhjid nra;jy; kpfTk;
,yF. ,J ,ae;jpuj;jpy; jq;fpapuhj nkhopahFk;. ,k; nkhopf;F nkhopngah;g;gpfs; mtrpakhFk;.
Example → C, C++, Java, Pascal, Fortran, COBOL
ehd;fhk; jiyKiwf; fzpdp nkhop 4GL
nra;epuy;fs; ahTk; fzpj FwpaPLfs; ,aw;if nkhopapid gad;gLj;jp vOjg;gLk;. kdpjd;
tpsq;fpf; nfhs;tJ ,yF. nra;epuy; epiwNtw;Wif Ntfk; FiwT fhuzk; Translator mtrpak;.
1GL,2GL cld; xg;gpLk; NghJ nra;epuy; vOJjy; kw;Wk; Nrhjid nra;jy; kpfTk; ,yF.
85 of 87
nra;epuyhf;f fl;lis gbtq;fs; (Program Paradigms)
nra;epuy; nkhopfs; nraw;gLk; tpjj;jpd; mbg;gilapy; mtw;iw ,uz;L gpujhd tiffshf
tifg;gLj;jyhk;. ,t;tifg;gLj;jy; fl;lisg; gbtq;fs; vdg;gLfpd;wJ.
1. fl;lisapLk; nkhopfs; (Imperative Language)
2. ntspapLk; nkhopfs; (Declarative Language)
Paradigm can also be termed as method to solve some problem or do some task.
Programming paradigm is an approach to solve problem using some
fl;lisapLk; nkhopfs;
programming language or also we can say it is a method to solve a problem using
tools and techniques
,J kpfTk; nghJthd that are available
tifapidr; rhu;e;[Link] us ,t;
following some approach.
tifapy; njhlupay; fl;lisfshf
(imperatives) nra;epuy; vOjg;gLfpd;wJ. NkYk; ,it %d;W tiffshf tifg;gLj;jg;gLfpd;wd.
▪ eilKiw (Procedural) – C
▪ nghUs; rhu;e;jJ (Object Oriented) – C++, Java, Objective-C, Python, Ruby, Simula (First OOP
Lang)
▪ rkhe;ju Kiwtopahf;fk; (Parallel Processing) – Java, NESL (One of the Oldest One)
ntspapLk; nkhopfs;
86 of 87
Runtime Error
njhlupay; tOf;fs; ,y;yhj nra;epuiy nraw;gLj;j Kaw;rpf;Fk; NghJ mJ Fwpj;j
nraw;ghl;il nra;ahJ. ,J nra;epuiy epiwNtw;Wk; NghJ cUthfpd;wJ.
Example: Devision by Zero Error, tl;by; ,y;yhj xU Nfhitapd; ngaiu jpwj;jy; my;yJ
mioj;jy;.
Logical Error
Fwpj;j igj;jd; nra;epuypy; FwpaPl;L hPjpahf vJtpjkhd tOf;fSk; ,d;wp nra;epuyhshpdhy;
,lg;gLfpd;w jtWfs; ,tw;Ws; mlq;Fk;. mjhtJ nra;epuypw;Fhpa ntspaPL ngwg;gLk;. Mdhy;
mt; ntspaPL jtwhdjhff; fhzg;gLk;. nrh ;nghUspay; tOf;fSld; $ba nra;epuyhdJ
,Wjp tiu ,aq;fp ntspaPl;bidj; jtwhfj; jUk;.
Example: NtnwhU Nfhg;gpid jpwe;J juTfis khw;wk; nra;jy;> $l;Lk; NghJ fopgly;>
ngUf;Fk; NghJ gpupgly;.
The End!
87 of 87