Skip to content

How to take continuous input in Python | Example code

Use While loop with True condition expression to take continuous input in Python. And break the loop using if statement and break statement.

while True:

   some_method()

Example take continuous input in Python

Simple example code gets user input repeatedly until want to quit.

while True:

    user_input = input("Enter something: ")
    if user_input == "quit":
        break

print(user_input)

Output:

How to take continuous input in Python

And if you want to store input data use this code.

input_string = ''
while 1:
    inp = input('Add to a string: ')
    if inp == 'quit':
        break
    input_string += inp

print(input_string)

Output:

Add to a string: Hello
Add to a string: quit
Hello

Do comment if you have any doubts or suggestions on this Python input topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

1 thought on “How to take continuous input in Python | Example code”

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading