I want to input multiple strings with new lines in Python 3.

Asked 2 years ago, Updated 2 years ago, 239 views

In Python 3, I want to "input" multiple strings with new lines.

For example, if the strings "Apple" and "Tangerine" are broken and entered as standard, I would like to substitute the variables "a" and "b" respectively.If possible, I would like to know if there are more than three standard inputs and how to represent them in a single line.

(Standard Input)
Apple returntangerinereturn

(Results)
Replace variable a with apple
Replace variable b with tangerine

python python3

2022-09-30 22:02

1 Answers

Take a line of standard input with the built-in function input().

a=input()
b = input()

If you do not know how many are entered (when the number is variable), it is recommended to keep the data in the list while repeating input().At this time, you must decide the conditions for repeated termination.

For example, if you want to continue reading EOF, you can write:

 lines=[ ]
while True:
    try:
        lines.append(input())
    except EOFError:
        break


2022-09-30 22:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.