English

What is the use of the next() function?

Advertisements

Question

What is the use of the next() function?

Short Answer
Advertisements

Solution

The next() function in Python is used to retrieve the next item from an iterator. If the iterator is exhausted, it raises a StopIteration exception. You can also provide a default value to be returned if the iterator is exhausted, preventing the exception. 

Syntax: 

next(iterator, default_value)
shaalaa.com
Creating a CSV File Using Notepad (or Any Text Editor)
  Is there an error in this question or solution?
Chapter 13: Python and CSV files - Evaluation [Page 266]
Advertisements
Share
Notifications



      Forgot password?
Use app×