2021/8/9(迭代器初始next())
import datetime
List_example = ["A", 1, lambda x: x+2]
it = iter(List_example)
it_1 = next(it)
it_2 = next(it)
it_3 = next(it)
it_3_example = it_3(2)
print("it_1:", it_1,"\n", "it_2:", it_2,"\n", "it_3:",it_3_example)
try:
it_4 = next(it)
except StopIteration:
print("It is end, assert StopIteration")
pass
A = "abcde"
start = datetime.datetime.now()
B = iter(A)
D = [next(B) for i in range(len(A))]
E = [x for x in A]
print(E)
print(D)
运行结果
it_1: A
it_2: 1
it_3: 4
It is end, assert StopIteration
['a', 'b', 'c', 'd', 'e']
['a', 'b', 'c', 'd', 'e']
二级目录
三级目录
|