-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions_next().py
40 lines (31 loc) · 928 Bytes
/
Functions_next().py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Python next() Function
# Example
# Create an iterator, and print the items one by one:
mylist = iter(["apple", "banana", "cherry"])
x = next(mylist)
print(x)
x = next(mylist)
print(x)
x = next(mylist)
print(x)
# Definition and Usage
# The next() function returns the next item in an iterator.
# You can add a default return value, to return if the iterable has reached to its end.
# Syntax
# next(iterable, default)
# Parameter Values
# Parameter Description
# iterable Required. An iterable object.
# default Optional. An default value to return if the iterable has reached to its end.
# More Examples
# Example
# Return a default value when the iterable has reached to its end:
mylist = iter(["apple", "banana", "cherry"])
x = next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)
x = next(mylist, "orange")
print(x)