1、yield 暂存为list def max_generator(numbers): current_max = 0 for i in numbers: current_max = max(i, current_max) yield current_max; a = [3, 4, 6, 2, 1, 9, 0, 7, 5, 8] results = list(max_generator(a)) print(results)