Table of Contents
Python Tutorial
Table of Contents
Python Tutorial
Iterators in Python in Hindi
What is Iterators in Python
Iterators ऐसे objects होता है जो हमे collections (जैसे: lists, tuples और dictionaries) के elements को बिना indexing के एक-एक करके traverse करने देते है, ये iterator protocol को implement करता है, जो __iter__() और __next__() methods से बना होता है।
Key Concepts of Iterators
Iterable
Iterable ऐसे object होते है जो अपने members (elements) को एक-एक करके return करने की capability रखते है (जैसे: lists, tuples, strings, aur dictionaries) इसमे __iter__() method होना चाहिए जो एक iterator return करे।
Iterator
Iterator एक ऐसा object होता है जो data का stream represent करता है, जब __next__() method call होता है तब ये एक-एक करके data return करता है।
Iterator Protocol
एक object को iterator तभी consider किया जाएगा जब उसमे __iter__() और __next__() method हो।
__iter__ Method
__iter__ method iterator object खुद return करता है, ये इसलिए भी जरूरी है ताकि एक iterator object को iterable के रूप में use किया जा सके।
__next__ Method
ये method, sequence (जैसे कोई list, tuple, string, etc.) का next item return करता है, जब end तक पहुँच जाता है तो ये StopIteration exception raise करता है जो signal देता है कि अब sequence में और item नहीं है।
Built-in Iterators
Python कई build-in iterators provide करता है जिसका use lists, tuples, strings और dictionaries में किया जाता है।
iter(): इस function का use एक iterable से iterator return कराने के लिए होता है।
next(): इस function का use iteration से nest item return कराने की लिए होता है।
Custom Iterators
हम custom iterators भी create कर सकते है इसके लिए हमे __iter__() और __next__() method को अपने class में implement करना होगा।
Generators
Generators, iterators बनाने का एक आसान तरीका होता है जिसमे functions और yield statement का use होता है। ये एक time में सिर्फ एक value ही generate करते है और हर value के बीच अपने state को maintain करते है।
Function Definition: my_generator function define किया गया है yield statement के साथ।
Yield: Yield एक value return करता है और next call के लिए अपने state को maintain करके function को pause करता है।
Generator Expressions: Generator expressions, generators को बनाने के लिए compact syntax provide करते है।
उम्मीद करते है कि आपको Python Iterators अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे,
- All Posts
- Artificial Intelligence
- Computer Fundamentals
- Computer Networks
- Data Analytics
- Data Science
- DBMS
- Deep Learning
- Digital Electronics
- DSA with Python
- Excel
- Exercise
- Git & Github
- Machine Learning
- Matplotlib
- Natural Language Processing
- NumPy
- Operating System
- Pandas-s
- Power BI
- Python Tutorial
- Scikit-learn
- Seaborn
- SQL & MySQL

Table of Contents All Chapters 1. Personal Area Network 2. Local Area Network 3. Campus Area Network 4. Metropolitan Area...

Table of Contents All Chapters 1. Data Communication 2. Types of Data Communication 2.1. Simplex 2.2....

Table of Contents All Chapters 1. Special Logic Gate 2. XOR Gate 2.1. XOR Gate Truth Table 3....

Table of Contents All Chapters 1. Universal Logic Gates 2. NOR Gate 2.1. NOR Gate Truth Table 3....

Table of Contents All Chapters 1. Logic Gate 2. AND Gate 2.1. AND Gate Truth Table 3. OR...

Table of Contents All Chapters 1. Simplification 2. Simplification using Boolean Algebra Theorems 3. Simplification using K-map Digital Electronics...

Table of Contents All Chapters 1. Identity Laws 2. Null Laws 3. Domination Laws 4. Idempotent Laws 5. Complement Laws...