Slices, Methods, Loops TRB CSI › Python Programming › slices, methods, loops

Slices, Methods, Loops

List Slicing என்பது ஒரு list-ல் இருந்து தேவையான portion அல்லது range of elements-ஐ எடுக்கும் technique. Simple definition: Slicing is used to extract a portion of a list.

Premium — locked Advanced 21 min 242 cards 56 programs 10 MCQs v5
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock

PYTHON LISTS - SLICES, METHOD……

Premium This card is part of the premium lesson. Unlock
Definition

List Slicing என்பது ஒரு list-ல் இருந்து தேவையான portion அல்லது rang……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a = [10, 20, 30, 40, 50] இதில் 20,……

Premium This card is part of the premium lesson. Unlock
Simple Explanation

List: Value : 10 20 30 40 50 Index : 0 1 2 3 4 நமக……

Premium This card is part of the premium lesson. Unlock
Important

Start index -> Included Stop index -> Excluded அதனா……

Premium This card is part of the premium lesson. Unlock
Explanation

list[start : stop : step] இதில் மூன்று பகுதிகள்: start -> எங்க……

Premium This card is part of the premium lesson. Unlock
List

1. BASIC SLICING…

Premium This card is part of the premium lesson. Unlock
Explanation

a = [10, 20, 30, 40, 50]…

Premium This card is part of the premium lesson. Unlock
Dry Run
a[1:4]
Output
Result
Algorithm

1. OMITTING START VALUE…

Premium This card is part of the premium lesson. Unlock

Start value கொடுக்கவில்லை என்றால் Python a……

Premium This card is part of the premium lesson. Unlock

இதன் meaning: a[0:3]…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. OMITTING STOP VALUE…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30, 40, 50]…

Premium This card is part of the premium lesson. Unlock

அதாவது: Index 2 முதல் last வரை…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. OMITTING BOTH START AND ST……

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock

இது complete list-ஐ copy செய்……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. STEP VALUE…

Premium This card is part of the premium lesson. Unlock

Step என்பது ஒவ்வொரு element-க்கும் இடையில் எவ்வ……

Premium This card is part of the premium lesson. Unlock
Dry Run

Start = 0 Stop = 6 Step = 2 Indic……

Premium This card is part of the premium lesson. Unlock
Output
Result
Algorithm

1. DEFAULT STEP…

Premium This card is part of the premium lesson. Unlock
Program
Step value கொடுக்கவில்லை என்றால்

So: a[1:4] actually behaves l……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. NEGATIVE SLICING…

Premium This card is part of the premium lesson. Unlock

Negative index மூலம் list-ன் end-லிருந்து slice செய்யலாம். a ……

Premium This card is part of the premium lesson. Unlock
Program
Example
Algorithm

1. REVERSE LIST USING SLICING…

Premium This card is part of the premium lesson. Unlock

மிக முக்கியமான Python concept……

Premium This card is part of the premium lesson. Unlock

இதில்: Start -> default Stop -……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. EVERY SECOND ELEMENT…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30, 40, 50, 60]…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. REVERSE WITH STEP -2…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30, 40, 50, 60]…

Premium This card is part of the premium lesson. Unlock

Flow: 60 -> 40 -> 20…

Premium This card is part of the premium lesson. Unlock
Important

Slicing rule: [start : stop :……

Premium This card is part of the premium lesson. Unlock
Remember

Start included Stop excluded…

Premium This card is part of the premium lesson. Unlock
Common Mistake

a = [10, 20, 30, 40] print(a[1:3]) பலர் output: [20……

Premium This card is part of the premium lesson. Unlock
Memory Trick

S S S Start Stop Step முக்கிய விதி……

Premium This card is part of the premium lesson. Unlock
Definition

List Methods என்பது Python list obje……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a.append(10) இங்கு: a -> list object append -> list method IMPORTAN……

Premium This card is part of the premium lesson. Unlock
List

1. append()…

Premium This card is part of the premium lesson. Unlock
Explanation

List-ன் end-ல் ஒரு element ad……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. extend()…

Premium This card is part of the premium lesson. Unlock

Multiple elements add செய்யும……

Premium This card is part of the premium lesson. Unlock
Output
Result
Output
Result

Memory: append -> one object ……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. insert()…

Premium This card is part of the premium lesson. Unlock

Specific position-ல் add செய்……

Premium This card is part of the premium lesson. Unlock
Explanation
Syntax

list.insert(index, value) a =……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. remove()…

Premium This card is part of the premium lesson. Unlock

Value based delete. a = [10, ……

Premium This card is part of the premium lesson. Unlock
Important

remove(20) இங்கு 20 என்பது va……

Premium This card is part of the premium lesson. Unlock
Important

1. pop()…

Premium This card is part of the premium lesson. Unlock
Important

Index based delete. a = [10, ……

Premium This card is part of the premium lesson. Unlock

pop() removed element-ஐ retur……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. pop() WITHOUT INDEX…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30] a.pop()…

Premium This card is part of the premium lesson. Unlock

Default: Last element remove…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. clear()…

Premium This card is part of the premium lesson. Unlock

All elements remove. a = [10,……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. index()…

Premium This card is part of the premium lesson. Unlock

ஒரு value எந்த position-ல் இர……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. count()…

Premium This card is part of the premium lesson. Unlock

ஒரு value எத்தனை முறை வருகிறத……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. sort()…

Premium This card is part of the premium lesson. Unlock

Ascending order-ல் arrange செ……

Premium This card is part of the premium lesson. Unlock

a.sort(reverse=True)…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. reverse()…

Premium This card is part of the premium lesson. Unlock

Current order-ஐ reverse செய்ய……

Premium This card is part of the premium lesson. Unlock
Important

reverse() என்பது descending s……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a = [30, 10, 20] a.reverse()…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. copy()…

Premium This card is part of the premium lesson. Unlock

List-ன் copy உருவாக்கும். a =……

Premium This card is part of the premium lesson. Unlock
Comparison

METHODS vs FUNCTIONS இந்த difference மிக முக்கியம். Methods Object மூலம் call செய்வோம். a.append(10……

Premium This card is part of the premium lesson. Unlock
Definition

ஒரு list-ல் உள்ள elements-ஐ one by one process செய்ய loop……

Premium This card is part of the premium lesson. Unlock
Definition

1. FOR LOOP WITH LIST…

Premium This card is part of the premium lesson. Unlock
Explanation

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock
Explanation

for i in a: இங்கு: First iteration -> i = 10 Second iteration -……

Premium This card is part of the premium lesson. Unlock
Dry Run
a = [10, 20, 30]

List values number மட்டும் இர……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. LOOP USING range() AND len……

Premium This card is part of the premium lesson. Unlock

List index-ஐ பயன்படுத்த வேண்ட……

Premium This card is part of the premium lesson. Unlock

returns: 3 So:…

Premium This card is part of the premium lesson. Unlock
Program
becomes

produces: 0, 1, 2 Then: a[0] ……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. PRINT INDEX AND VALUE…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. enumerate() WITH LIST…

Premium This card is part of the premium lesson. Unlock

Python-ல் index + value இரண்டும் simultan……

Premium This card is part of the premium lesson. Unlock
Program
இது

விட பல situations-ல் cleaner.…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. SUM LIST USING LOOP…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. FIND ODD NUMBERS…

Premium This card is part of the premium lesson. Unlock

a = [1, 2, 3, 4, 5]…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. SEARCH USING LOOP…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30, 40]…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. MODIFY ELEMENTS USING INDE……

Premium This card is part of the premium lesson. Unlock

Example: அனைத்து values-ஐ dou……

Premium This card is part of the premium lesson. Unlock
Program
இந்த code

list values-ஐ direct-ஆ change……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock

ஏன்? i temporary loop variable. Origi……

Premium This card is part of the premium lesson. Unlock

பயன்படுத்தலாம்.…

Premium This card is part of the premium lesson. Unlock
Algorithm

1. WHILE LOOP WITH LIST…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30]…

Premium This card is part of the premium lesson. Unlock
Program
Outer loop

First: row = [1, 2] Inner loop: 1……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. break WITH LIST LOOP…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30, 40]…

Premium This card is part of the premium lesson. Unlock

30 வந்ததும் loop முழுவதும் st……

Premium This card is part of the premium lesson. Unlock
Algorithm

1. continue WITH LIST LOOP…

Premium This card is part of the premium lesson. Unlock

a = [10, 20, 30, 40]…

Premium This card is part of the premium lesson. Unlock

30 மட்டும் skip.…

Premium This card is part of the premium lesson. Unlock
Comparison

for loop for i in a: Value di……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

Index கிடைக்கும். 0 1 2 Then ……

Premium This card is part of the premium lesson. Unlock
Important

List loops-ல் மிக முக்கியமான concepts: for x in list gives elements. range(len(list)) gives indices. enumerat……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 1

Wrong: a = [10, 20, 30] for i in range(len(a) + 1): print(a[i]) Problem: l……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 2

a = [10, 20, 30] i = 0 while i < len(a): print(a[i]) இதில்: i……

Premium This card is part of the premium lesson. Unlock
Common Mistake
Common error 3

for i in a: a.remove(i) Loop ஓடும்போது……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

a = [1, 2, 3, 4]…

Premium This card is part of the premium lesson. Unlock
Explanation

Unexpected result வரலாம். Loop செய……

Premium This card is part of the premium lesson. Unlock
Memory Trick

Slicing [start : stop : step] Start -> take Stop -> leave Step -> jump Methods Add: append extend insert Dele……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 1

What is the output? a = [10, 2……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 2

a = [1, 2, 3, 4] print(a[::-1……

Premium This card is part of the premium lesson. Unlock
MCQ

Which method adds many elemen……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 4

a = [10, 20, 30] for i in a: ……

Premium This card is part of the premium lesson. Unlock
TRB Point
Question 5

What does this loop produce? for ……

Premium This card is part of the premium lesson. Unlock
Interview Point

Why is slicing useful? Slicing allows us to extract a specific portion of a l……

Premium This card is part of the premium lesson. Unlock
Explanation
Example

20 Slice: a[1:3] returns anot……

Premium This card is part of the premium lesson. Unlock
Program
Example
Explanation

gives the value directly.…

Premium This card is part of the premium lesson. Unlock
Explanation

gives the index.…

Premium This card is part of the premium lesson. Unlock
MCQ

Which is the correct slicing ……

Premium This card is part of the premium lesson. Unlock
MCQ

Stop index in slicing is:…

Premium This card is part of the premium lesson. Unlock
MCQ

What is the output? a = [1, 2……

Premium This card is part of the premium lesson. Unlock
MCQ

Which expression reverses a l……

Premium This card is part of the premium lesson. Unlock
MCQ

Which method returns the posi……

Premium This card is part of the premium lesson. Unlock
MCQ

remove() works based on:…

Premium This card is part of the premium lesson. Unlock
MCQ

pop() without an index remove……

Premium This card is part of the premium lesson. Unlock
MCQ

enumerate() provides:…

Premium This card is part of the premium lesson. Unlock
MCQ

Which method reverses current……

Premium This card is part of the premium lesson. Unlock
Practice

Predict the output. 1. a = [10, 20, 30, 40, 50] print(a[2:5]) 2. a = [1, 2, 3, 4, 5, 6] print(a[1::2]) 3. a =……

Premium This card is part of the premium lesson. Unlock
Summary

LIST SLICING a[start:stop:step] Key rules: Start -> included Stop -> excluded Step -> movement Examples: a[1:……

Premium This card is part of the premium lesson. Unlock
Text size
17px
Theme
Contents
Print / PDF
Program