1# test next(iter, default) 2 3try: 4 next(iter([]), 42) 5except TypeError: # 2-argument version not supported 6 print('SKIP') 7 raise SystemExit 8 9print(next(iter([]), 42)) 10print(next(iter(range(0)), 42)) 11print(next((x for x in [0] if x == 1), 43)) 12 13def gen(): 14 yield 1 15 yield 2 16 17g = gen() 18print(next(g, 42)) 19print(next(g, 43)) 20print(next(g, 44)) 21 22class Gen: 23 def __init__(self): 24 self.b = False 25 26 def __next__(self): 27 if self.b: 28 raise StopIteration 29 self.b = True 30 return self.b 31 32g = Gen() 33print(next(g, 44)) 34print(next(g, 45)) 35