Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiple Input() in one line Python

I was wondering if its possible to write instead of many variables and inputs in different lines of code, write all in one sentence.

Usually I’ve seen and wrote like this:

VARIABLE1 = input(var1)
VARIABLE2 = input(var2)
print(var1 + var2)

So the prompt will ask you to write 2 values in diferent sentences, because its been written that way. But is it possible to have the same output in the prompt (asking values in diferent senteces) making just one input()?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ve been reading about .split(), map() and lists, but the output is that the values have to be written in one sentence.

>Solution :

You can use tuple assignment:

name, age = input('What is your name? '), int(input('How old are you? '))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

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

Continue reading