stopword = ''
str = ''
for line in iter(input, stopword):
str += line + '\n'
print(str)
iter(object, sentinel)
Python官方文档对于这种形式的解释是:“ If the second argument, sentinel, is given, then object must be a callable object. The iterator created in this case will call object with no arguments for each call to its [__ next __()](https://docs.python.org/3/library/stdtypes.html#iterator.__ next __ "iterator.__ next __") method; if the value returned is equal to sentinel,StopIteration will be raised, otherwise the value will be returned.”。
这句话的意思是说:如果传递了第二个参数,则object必须是一个可调用的对象(如,函数)。此时,iter创建了一个迭代器对象,每次调用这个迭代器对象的 __ next __() 方法时,都会调用object。
如果__ next __的返回值等于sentinel,则抛出StopIteration异常,否则返回下一个值。