I enter into the console a string of numbers. How to set the sign of the end of the input? For example, read until the character '0', etc.

2 answers 2

 In [2]: for i in iter(input, 'stop'): ...: print('Вы ввели: ' + i) ...: hello Вы ввели: hello world Вы ввели: world stop 

From the documentation :

Return an iterator object. The first argument is interpreted very differently. It is a collection of objects that supports the iteration protocol (the __iter__() method). If it doesn’t support either of those protocols, TypeError is raised. The object is a callable object. The iterator is set to __next__() method; If the value is returned, it is a StopIteration will be raised.

    So, for example:

     lines = [] while True: line = input('Введите строку: ') if line == '0': break else: lines.append(line) print(lines)