+ 1

What does iter() and next() do in python

I searched on google how that iter() and next() do in python after seeing it in a challenge on python but i still dont get it

3rd Mar 2024, 11:17 AM
Yassine Belm
Yassine Belm - avatar
4 odpowiedzi
+ 4
an iterator is an object used to iterate across iterable objects such as lists, tuples, dicts, and sets. the iter() method is used to initialize the iterator object. iteration is accomplished through the usage of the next() method. you can find a really good and simple example here also: https://www.programiz.com/JUMP_LINK__&&__python__&&__JUMP_LINK-programming/iterator
3rd Mar 2024, 11:37 AM
Mihaly Nyilas
Mihaly Nyilas - avatar
+ 4
Yassine Belm using the references that Mihaly Nyilas and Bob_Li brought up I created this code for a quick easy to follow explanation https://sololearn.com/compiler-playground/clBD6dRUxX2j/?ref=app
4th Mar 2024, 2:05 AM
BroFar
BroFar - avatar
+ 2
don't forget about generators while you are learning about iterable objects. here is a good explanation in SO https://stackoverflow.com/questions/2776829/difference-between-pythons-generators-and-iterators
3rd Mar 2024, 2:17 PM
Bob_Li
Bob_Li - avatar
+ 1
What i understand that you copie the iterable objects in variables like (iterator=iter(name)) than you choose one character of the variable using next()
3rd Mar 2024, 12:15 PM
Yassine Belm
Yassine Belm - avatar