Iteration in Python - for Loop TRB CSI › Python Programming › Iteration - for

Iteration in Python - for Loop

Iteration என்பது ஒரு set of statements-ஐ repeatedly execute செய்வது. தமிழில்: ஒரே code-ஐ மீண்டும் மீண்டும் execute செய்வதுதான் Iteration. Python-ல் முக்கிய iteration statements: for while இப்போது for loop-ஐ முழுமையாக பார்க்கலாம்.

Premium — locked Advanced 18 min 165 cards 20 programs 8 MCQs v3
This is a premium lesson. You can see the shape of every card — unlock to read them. Unlock
Definition

Iteration என்பது ஒரு set of statements-ஐ repeatedly execute செய்வது. தமிழில்: ஒரே code-ஐ ம……

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

Suppose: Hello என்பதை 5 times print செய்ய வேண்டும். Without loop: print("Hello") print(……

Premium This card is part of the premium lesson. Unlock

இதுதான் iteration.…

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

for loop flow: Sequence / Range ↓ Take one value ↓ Stor……

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

Python for loop என்பது ஒரு sequence-ல் உள்ள ஒவ்வொரு item-ஐ one by one ……

Premium This card is part of the premium lesson. Unlock
Program
Example
Syntax
Syntax breakdown
Syntax
இதில்
Syntax
அடுத்த line
Explanation

Indentation உள்ளதால் இது loop……

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

range(5) என்றால்: 0, 1, 2, 3, 4 5 inc……

Premium This card is part of the premium lesson. Unlock
Program
Step by step
Explanation

Then sequence finished. Loop ……

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

இந்த program-ல்: for i in range(5): print(i) ……

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

for loop உடன் மிகவும் commonly பயன்படு……

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

1. range(stop) 2. range(start……

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

Values: 0 1 2 3 4 Default sta……

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

range(5) means: Start = 0 Sto……

Premium This card is part of the premium lesson. Unlock
Output
Result
Program
Example
Program
Here
Program
Example
Program
Here
Explanation
Step meaning

step என்பது ஒவ்வொரு iteration-க்கும் ……

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

Every time: +2…

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

Reverse order-ல் loop செய்ய negativ……

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

for i in range(1, 5, -1): pri……

Premium This card is part of the premium lesson. Unlock

ஏன்? Start: 1 Stop: 5 ஆனால் step: -1 நாம் 1-ல……

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

for loop range() மட்டும் அல்ல. List-ஐ நேரடியாக iter……

Premium This card is part of the premium lesson. Unlock
Dry Run
languages = ["Python", "C", "Java"]
Important

இதில் x automatic-ஆ list-ல் உள்ள ……

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

data = (10, 20, 30) for x in ……

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

data = {10, 20, 30} for x in ……

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

ஆனால் Set என்பது unordered colle……

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

String கூட sequence. for ch i……

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

String-ல் ஒவ்வொரு character-ம……

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

Dictionary: student = { "name"……

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

Dictionary-ஐ நேரடியாக iterate……

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

Values வேண்டுமெனில்: student = { "nam……

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

Key + value இரண்டும் வேண்டுமெனில்: student = { "na……

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

இந்த line: for key, value in student.items(): இங்கே items() ஒவ்வொரு item-ஐ: (key, valu……

Premium This card is part of the premium lesson. Unlock
Program
Program 1 to 5
Explanation
Why range 1 6

5 வரை print செய்ய வேண்டும். ஆனால் stop value excluded. ……

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

for i in range(2, 11, 2): pri……

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

for i in range(1, 10, 2): pri……

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

total = 0 for i in range(1, 6……

Premium This card is part of the premium lesson. Unlock
Table
Multiplication table

n = 5…

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

for i in range(1, 11): print(……

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

Factorial: 5! = 5 × 4 × 3 × 2……

Premium This card is part of the premium lesson. Unlock
Output
Result
Explanation
For with if

for loop உள்ளே if பயன்படுத்தலா……

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

Take i ↓ Check i % 2 == 0 ↓ T……

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

break என்பது loop-ஐ உடனடியாக stop செய்……

Premium This card is part of the premium lesson. Unlock
Dry Run
Dry run break
Explanation
Continue

continue என்பது current iteration மட்டும் skip செய்து n……

Premium This card is part of the premium lesson. Unlock
Comparison
Break vs continue
Explanation
Pass

pass என்பது do nothing placeholder statement. for ……

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

break ↓ Entire loop stop contin……

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

Python-ல் for loop-க்கு else பயன்படுத்த……

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

Loop normally complete ஆனால் else execu……

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

Completed print ஆகாது.…

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

ஒரு for loop-க்கு உள்ளே மற்றொ……

Premium This card is part of the premium lesson. Unlock
Dry Run
Dry run nested
Explanation
Total iterations

Outer loop: 2 times Inner loo……

Premium This card is part of the premium lesson. Unlock
Program
Pattern program
Explanation
Enumerate

ஒரு sequence-ல் value மட்டுமல்ல index-உம் வேண்டுமெனில் enumerate() ……

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

enumerate(): Index + Value இர……

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

Index 1-லிருந்து தொடங்க: languages = ["Python", "C"……

Premium This card is part of the premium lesson. Unlock
Comparison
For loop vs while loop
Important

Python for loop என்பது C/C++ for loop போல exactly இல்லை. C/C++: for(initiali……

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

Colon missing Wrong: for i in ra……

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

Indentation missing Wrong: for i in……

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

Expecting stop value for i in range(5): ……

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

Wrong range() Wrong: range[5] Corre……

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

Wrong keyword Wrong: for i of ra……

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

Basic for: FOR ↓ Take one val……

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

for variable in sequence: Easy Tamil memory……

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

1. for loop எதற்காக?…

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

Repeated execution / iteratio……

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

1. Python for loop commonly i……

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

Sequence / iterable.…

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

1. range(5) values?…

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

0, 1, 2, 3, 4…

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

1. range() default start?…

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

0…

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

1. range() default step?…

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

1…

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

1. Stop value included?…

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

No…

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

1. Loop immediately stop செய்……

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

break…

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

1. Current iteration மட்டும் ……

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

continue…

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

1. Do-nothing statement?…

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

pass…

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

1. for inside for?…

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

Nested for loop…

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

Question: What is iteration? Iteration is the repeated execution of a block of code. Question: What is the Py……

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

range() இல்லாமலேயே for loop பயன்படுத்தலாம். Question: What values can come after in? Any iterable object. Exa……

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

Which keyword is used for ite……

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

range(1, 5) produces:…

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

Default start value of range(……

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

Default step value?…

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

Which statement exits a loop?…

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

Which statement skips current……

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

4 6 1. A loop inside another ……

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

What does this iterate over? ……

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

Print 1 to 10 for i in range(……

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

Print 10 to 1 for i in range(……

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

Even Numbers for i in range(2……

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

Odd Numbers for i in range(1,……

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

Sum 1 to 10 total = 0 for i i……

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

Iteration │ ├── for └── while for syntax: for variable in sequence: statement Possible sequences: range list ……

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
Explanation
Short description

Iteration என்பது ஒரு block of code-ஐ repeated-ஆ execute செய்வது. Python for loop ஒரு iterable அல்லது sequence……

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