建议:def peek(iterable): try: first = next(iterable) except StopIteration: return None return first, itertools.chain([first], iterable)用法:res = peek(mysequence)if res is None: # sequence is empty. Do stuff.else: first, mysequence = res # Do something with first, maybe? # Then iterate over the sequence: for element in mysequence: # etc.