1

e.g I want to the user to assign numbers to 3 variables

a = input()
b = input()
c = input()

I know you can do it like this;

a,b,c = input()
>>>1,2,3

but I need it to be asked on separate lines like the first example.

Is there a way to do something like this;

a,b,c = input() for range(3)
1
  • Store them in a dictionary. Commented Jun 12, 2020 at 10:58

2 Answers 2

4

This will work:

a,b,c = (input() for _ in range(3))

repl.it link: http://repl.it/@HarunYlmaz/input-comprehension (Thanks to @Harun Yimaz in the comments below)

Sign up to request clarification or add additional context in comments.

1 Comment

Here's a working repl.it: repl.it/@HarunYlmaz/input-comprehension
2

Instead of splattering your global scope, use a dict instead:

dct = {key: input() for key in ["a", "b", "c"]}
print(dct)

2 Comments

Sorry I'm fairly new to programming, can you expand on what you mean by "splattering your global scope"? Do you just mean don't waste/ use unnecessary global scope variables ?
@jackwquinton: Yes, exactly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.