Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

next() python

#next() returns the next number in an iterator
#iter() returns an iterator of the given object

l = ['apple', 'banana', 'cherry', 'grape']
l_iterable = iter(l) #makes an iterator from l list

next_value = next(l_iterable) #gets the first value
print(next_value) #prints 'apple'

next_value = next(l_iterable) #gets the next value
print(next_value) #prints 'banana'

next_value = next(l_iterable) #gets the next value
print(next_value) #prints 'cherry'

next_value = next(l_iterable) #gets the next value
print(next_value) #prints 'grape'
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
9+6 =