Post

PythonPython

c
cayrel rings

Posted on 5th March 2024|42 views

0
votes

Python Hasnext

Does python iterators got the hasNext method?

Answers
P
Harshel Mike

Posted on 5th March 2024

There is an alternative for StopIteration by utilising next(iteration, default_value)

Example:

>>> a = iter('hey') 

>>> print next(a, None) 

>>> print next(a, None) 

>>> print next(a, None) 

y

>>> print next(a, None) 

None 

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos